Skip to content

Commit

Permalink
Bug fix (GH pandas-dev#23078)
Browse files Browse the repository at this point in the history
  • Loading branch information
makbigc committed Dec 18, 2018
1 parent 216986d commit f4315ac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ Datetimelike
- Bug in :class:`DatetimeIndex` where constructing a :class:`DatetimeIndex` from a :class:`Categorical` or :class:`CategoricalIndex` would incorrectly drop timezone information (:issue:`18664`)
- Bug in :class:`DatetimeIndex` and :class:`TimedeltaIndex` where indexing with ``Ellipsis`` would incorrectly lose the index's ``freq`` attribute (:issue:`21282`)
- Clarified error message produced when passing an incorrect ``freq`` argument to :class:`DatetimeIndex` with ``NaT`` as the first entry in the passed data (:issue:`11587`)
- Bug in :class:`PeriodIndex` when comparing indexes of different lengths, ValueError is not raised (:issue:`23078`)

Timedelta
^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def wrapper(self, other):
elif isinstance(other, cls):
self._check_compatible_with(other)

if other.ndim > 0 and len(self) != len(other):
raise ValueError('Lengths must match to compare')

if not_implemented:
return NotImplemented
result = op(other.asi8)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/period/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ def test_insert(self):
result = period_range('2017Q1', periods=4, freq='Q').insert(1, na)
tm.assert_index_equal(result, expected)

def test_comp_op(self):
# GH 23078
index = period_range('2017', periods=12, freq="A-DEC")
with pytest.raises(ValueError, match="Lengths must match"):
index <= index[[0]]


def test_maybe_convert_timedelta():
pi = PeriodIndex(['2000', '2001'], freq='D')
Expand Down

0 comments on commit f4315ac

Please sign in to comment.