I encountered a strange error when using adtk's plot method: ValueError: Multi-dimensional indexing (e.g. obj[:, None]) is no longer supported. Convert to a numpy array before indexing instead
Opened this issue · 0 comments
My code is:
`
df = pd.read_csv('cleaned_data/原始值-周均价.csv')
df['date'] = pd.to_datetime(df['date'])
df.set_index('date',inplace=True)
df = validate_series(df)
from adtk.data import validate_series
from adtk.visualization import plot
from adtk.transformer import RollingAggregate
from adtk.transformer import DoubleRollingAggregate
from adtk.detector import ThresholdAD
threshold_ad = ThresholdAD(high=10, low=5)
anomalies = threshold_ad.detect(df)
plot(df, anomaly=anomalies, ts_linewidth=1, ts_markersize=3, anomaly_markersize=5, anomaly_color='red', anomaly_tag="marker");
`
I encountered an error:
`
ValueError Traceback (most recent call last)
Cell In[25], line 18
13 threshold_ad = ThresholdAD(high=10, low=5)
14 anomalies = threshold_ad.detect(df)
---> 18 plot(df, anomaly=anomalies, ts_linewidth=1, ts_markersize=3, anomaly_markersize=5, anomaly_color='red', anomaly_tag="marker");
File ~\anaconda3\envs\d2l\lib\site-packages\pandas\core\indexers\utils.py:341, in disallow_ndim_indexing(result)
333 """
334 Helper function to disallow multi-dimensional indexing on 1D Series/Index.
335
(...)
338 in GH#30588.
339 """
340 if np.ndim(result) > 1:
--> 341 raise ValueError(
342 "Multi-dimensional indexing (e.g. obj[:, None]
) is no longer "
343 "supported. Convert to a numpy array before indexing instead."
344 )
ValueError: Multi-dimensional indexing (e.g. obj[:, None]
) is no longer supported. Convert to a numpy array before indexing instead.
`
My version information:
adtk==0.6.2
I have made the following solutions, but none of them can be solved:
- I asked chatgpt, and it told me to switch to an array, but although I knew that the plot method required df, I still tried an array, and it was really an error.