My code is breaking at the following assert:
assert(type(series_one) == pandas.TimeSeries)
It seems the type I pass it is a 'pandas.core.series.Series', but the index of said series is 'pandas.tseries.index.DatetimeIndex'.
How can I fix this?
My code is breaking at the following assert:
assert(type(series_one) == pandas.TimeSeries)
It seems the type I pass it is a 'pandas.core.series.Series', but the index of said series is 'pandas.tseries.index.DatetimeIndex'.
How can I fix this?
There are two confusing points here. First, a pandas.Series
has an index, and it has values. The index may have varying types like CategoricalIndex
, MultiIndex
, TimeDeltaIndex
and your DatetimeIndex
.
Second, in your assertion, you type check the entire series, not the index. Moreover, it is recommended to use isinstance
for type checking, see here for more:
assert(isinstance(series_one, pandas.Series))
To check for a series, you used pandas.TimeSeries
but this is depreciated and should be replaced with pandas.Series
:
# creating pandas.TimeSeries
dummy = pd.TimeSeries([1,2,3])
FutureWarning: TimeSeries is deprecated. Please use Series
A future warning is printed automatically indicating that TimeSeries
should not be used in future.
To sum up, get your head around what you want to check in your assertion, either the entire Series or the index of the Series. In case you want to check for a Series, then use pandas.Series
instead of TimeSeries.