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

DatetimeIndex/TimedeltaIndex add/sub zero-dim arrays incorrect #19012

Closed
jbrockmendel opened this Issue Dec 31, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@jbrockmendel
Member

jbrockmendel commented Dec 31, 2017

Opening this mainly to get the appropriate reference for the upcoming PR.

Setup:

dti = pd.date_range('2016-01-01', periods=3, freq='H')
one = np.array(1)

0.21.1:

>>> dti + one
DatetimeIndex(['2016-01-01 00:00:00.000000001',
               '2016-01-01 01:00:00.000000001',
               '2016-01-01 02:00:00.000000001'],
              dtype='datetime64[ns]', freq='H')
>>> dti.freq = None
>>> dti + one
DatetimeIndex(['2016-01-01 00:00:00.000000001',
               '2016-01-01 01:00:00.000000001',
               '2016-01-01 02:00:00.000000001'],
              dtype='datetime64[ns]', freq=None)

Master (see #19011)

>>> dti + one
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/indexes/datetimelike.py", line 685, in __add__
    elif is_offsetlike(other):
  File "pandas/core/dtypes/common.py", line 294, in is_offsetlike
    elif (is_list_like(arr_or_obj) and len(arr_or_obj) and
TypeError: len() of unsized object
@jreback

This comment has been minimized.

Contributor

jreback commented Dec 31, 2017

0.21.1 is wrong.

this is correct

n [13]: dti = pd.date_range('2016-01-01', periods=3, freq='H')
    ...: one = np.array(1)
    ...: 

In [14]: dti
Out[14]: 
DatetimeIndex(['2016-01-01 00:00:00', '2016-01-01 01:00:00',
               '2016-01-01 02:00:00'],
              dtype='datetime64[ns]', freq='H')

In [15]: dti + 1
Out[15]: 
DatetimeIndex(['2016-01-01 01:00:00', '2016-01-01 02:00:00',
               '2016-01-01 03:00:00'],
              dtype='datetime64[ns]', freq='H')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment