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

Series[datetime64] - PeriodIndex vs DatetimeIndex - PeriodIndex #18850

Closed
jbrockmendel opened this Issue Dec 19, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@jbrockmendel
Member

jbrockmendel commented Dec 19, 2017

PeriodIndex w/ Series is allowed, PeriodIndex w/ DatetimeIndex is not. Is this intentional? If not, which should be made to match the other?

>>> dti = pd.date_range('2016-01-01', periods=3)
>>> ser = pd.Series(dti)
>>> pi = dti.to_period()

>>> ser - pi
0   0 days
1   0 days
2   0 days
dtype: timedelta64[ns]

>>> dti - pi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/indexes/datetimelike.py", line 724, in __sub__
    typ2=type(other).__name__))
TypeError: cannot subtract DatetimeIndex and PeriodIndex

>>> pi - ser
0   0 days
1   0 days
2   0 days
dtype: timedelta64[ns]

>>> pi - dti
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/indexes/datetimelike.py", line 731, in __rsub__
    return -(self - other)
  File "pandas/core/indexes/datetimelike.py", line 724, in __sub__
    typ2=type(other).__name__))
TypeError: cannot subtract DatetimeIndex and PeriodIndex
@jbrockmendel

This comment has been minimized.

Member

jbrockmendel commented Dec 28, 2017

It looks like this is caused by a line in ops._TimeOp._convert_to_array

        elif inferred_type == 'integer':
            # py3 compat where dtype is 'm' but is an integer
            if values.dtype.kind == 'm':
                values = values.astype('timedelta64[ns]')
            elif isinstance(values, pd.PeriodIndex):
                values = values.to_timestamp().to_series()
@jbrockmendel

This comment has been minimized.

Member

jbrockmendel commented Dec 31, 2017

@jreback if this can be confirmed as being incorrect behavior for Series, then the remaining point of contention in #18960 can be rendered moot.

@jreback

This comment has been minimized.

Contributor

jreback commented Dec 31, 2017

series w pi is wrong doesn’t make any sense

@jreback jreback modified the milestones: Next Major Release, 0.23.0 Jan 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment