Skip to content

Commit f4315ac

Browse files
committed
Bug fix (GH pandas-dev#23078)
1 parent 216986d commit f4315ac

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

doc/source/whatsnew/v0.24.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,7 @@ Datetimelike
13661366
- Bug in :class:`DatetimeIndex` where constructing a :class:`DatetimeIndex` from a :class:`Categorical` or :class:`CategoricalIndex` would incorrectly drop timezone information (:issue:`18664`)
13671367
- Bug in :class:`DatetimeIndex` and :class:`TimedeltaIndex` where indexing with ``Ellipsis`` would incorrectly lose the index's ``freq`` attribute (:issue:`21282`)
13681368
- 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`)
1369+
- Bug in :class:`PeriodIndex` when comparing indexes of different lengths, ValueError is not raised (:issue:`23078`)
13691370

13701371
Timedelta
13711372
^^^^^^^^^

pandas/core/arrays/period.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def wrapper(self, other):
6868
elif isinstance(other, cls):
6969
self._check_compatible_with(other)
7070

71+
if other.ndim > 0 and len(self) != len(other):
72+
raise ValueError('Lengths must match to compare')
73+
7174
if not_implemented:
7275
return NotImplemented
7376
result = op(other.asi8)

pandas/tests/indexes/period/test_period.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,12 @@ def test_insert(self):
561561
result = period_range('2017Q1', periods=4, freq='Q').insert(1, na)
562562
tm.assert_index_equal(result, expected)
563563

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

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

0 commit comments

Comments
 (0)