Skip to content
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

comparison between two PeriodIndexes doesn't validate length #23078

Closed
TomAugspurger opened this issue Oct 10, 2018 · 4 comments · Fixed by #24397
Closed

comparison between two PeriodIndexes doesn't validate length #23078

TomAugspurger opened this issue Oct 10, 2018 · 4 comments · Fixed by #24397
Labels
Bug Period Period data type
Milestone

Comments

@TomAugspurger
Copy link
Contributor

In [5]: idx = pd.period_range('2017', periods=12, freq="A-DEC")

In [6]: idx <= idx[[0]]
Out[6]:
array([ True, False, False, False, False, False, False, False, False,
       False, False, False])

This should raise.

Both DatetimeIndex and TimedeltaIndex do raise

In [8]: idx <= idx[[0]]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-8a2a887e6efd> in <module>
----> 1 idx <= idx[[0]]

~/sandbox/pandas/pandas/core/indexes/datetimes.py in wrapper(self, other)
     90
     91     def wrapper(self, other):
---> 92         result = getattr(DatetimeArrayMixin, opname)(self, other)
     93         if is_bool_dtype(result):
     94             return result

~/sandbox/pandas/pandas/core/arrays/datetimes.py in wrapper(self, other)
    133             else:
    134                 self._assert_tzawareness_compat(other)
--> 135                 result = meth(self, np.asarray(other))
    136
    137             result = com.values_from_object(result)

~/sandbox/pandas/pandas/core/arrays/datetimelike.py in cmp_method(self, other)
     51         if isinstance(other, (np.ndarray, ABCIndexClass, ABCSeries)):
     52             if other.ndim > 0 and len(self) != len(other):
---> 53                 raise ValueError('Lengths must match to compare')
     54
     55         if needs_i8_conversion(self) and needs_i8_conversion(other):

ValueError: Lengths must match to compare
@TomAugspurger TomAugspurger added the Period Period data type label Oct 10, 2018
@TomAugspurger
Copy link
Contributor Author

cc @jbrockmendel

@jorisvandenbossche
Copy link
Member

I think we had this before on other data structures (Index, Series ?) as well, at least I seem to remember something about it (long time ago, PeriodIndex might be an oversight). Only thing I can quickly find is #12346

@jbrockmendel
Copy link
Member

Should be fixed in the same pass as #21793. Possibly also #19804, #19088, #23063.

@jorisvandenbossche
Copy link
Member

So we indeed fixed this at a certain point of indexes in general: pandas.pydata.org/pandas-docs/stable/whatsnew.html#changes-to-index-comparisons

makbigc added a commit to makbigc/pandas that referenced this issue Nov 25, 2018
@jreback jreback added this to the 0.24.0 milestone Nov 28, 2018
@jreback jreback modified the milestones: 0.24.0, Contributions Welcome Dec 9, 2018
makbigc added a commit to makbigc/pandas that referenced this issue Dec 18, 2018
makbigc added a commit to makbigc/pandas that referenced this issue Dec 23, 2018
@jreback jreback modified the milestones: Contributions Welcome, 0.24.0 Dec 23, 2018
makbigc added a commit to makbigc/pandas that referenced this issue Dec 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Period Period data type
Projects
None yet
4 participants