Skip to content

series created with DatetimeIndex when index is [None] #7431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dbew opened this issue Jun 11, 2014 · 3 comments · Fixed by #7435
Closed

series created with DatetimeIndex when index is [None] #7431

dbew opened this issue Jun 11, 2014 · 3 comments · Fixed by #7435
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Milestone

Comments

@dbew
Copy link
Contributor

dbew commented Jun 11, 2014

This looks like a change from 0.13.1 to HEAD. If you create a series like this:

pd.Series(index=np.array([None]))

Then in 0.13.1 the result is:

Out[16]: 
NaN   NaN
dtype: float64

In [19]: x.index.dtype
Out[19]: dtype('O')

In [20]: type(x.index)
Out[20]: pandas.core.index.Index

but in HEAD the result is

Out[191]: 
NaT   NaN
dtype: float64

In[192]: x.index.dtype
Out[192]: dtype('<M8[ns]')

In[193]: type(x.index)
Out[193]: pandas.tseries.index.DatetimeIndex

So the index has changed from Index/object to DatetimeIndex/datetime64.

@dbew
Copy link
Contributor Author

dbew commented Jun 11, 2014

Running through the construction of a pd.Series object in the debugger, it looks like this is happening in Series._set_axis because is_all_dates is True for an index with just None in it.

    def _set_axis(self, axis, labels, fastpath=False):
        """ override generic, we want to set the _typ here """

        if not fastpath:
            labels = _ensure_index(labels)

        is_all_dates = labels.is_all_dates
        if is_all_dates:
            from pandas.tseries.index import DatetimeIndex
            from pandas.tseries.period import PeriodIndex
            if not isinstance(labels, (DatetimeIndex, PeriodIndex)):
                labels = DatetimeIndex(labels)

        .....

Constructing an Index manually confirms this:

i = pd.Index(np.array([None]))
i.is_all_dates    
Out[208]: True

But is_all_dates just defers to is_datetime_array which I think is cimported from numpy

@dbew
Copy link
Contributor Author

dbew commented Jun 11, 2014

Looks like it's PR 6341 which made the change:

@jreback
Copy link
Contributor

jreback commented Jun 11, 2014

no is_datetime_array is defined in src/inference.pyx; a single element None in this context should be simply nan. hmm.

cc @immerrr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants