-1

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?

jono
  • 171
  • 1
  • 1
  • 9
  • your question makes little sense, you're asking about determining whether something is a timeseries or a series and then ask why the index is a datetimeindex, why should this be a surprise? – EdChum Mar 09 '17 at 09:04

1 Answers1

0

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.

Community
  • 1
  • 1
pansen
  • 6,433
  • 4
  • 19
  • 32