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 Nov 25, 2018
1 parent a7b187a commit 7831b98
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
Expand Up @@ -1210,6 +1210,7 @@ Datetimelike
- Bug in :class:`DatetimeIndex` where calling ``np.array(dtindex, dtype=object)`` would incorrectly return an array of ``long`` objects (:issue:`23524`)
- Bug in :class:`Index` where passing a timezone-aware :class:`DatetimeIndex` and `dtype=object` would incorrectly raise a ``ValueError`` (:issue:`23524`)
- Bug in :class:`Index` where calling ``np.array(dtindex, dtype=object)`` on a timezone-naive :class:`DatetimeIndex` would return an array of ``datetime`` objects instead of :class:`Timestamp` objects, potentially losing nanosecond portions of the timestamps (:issue:`23524`)
- 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
Expand Up @@ -73,6 +73,9 @@ def wrapper(self, other):
msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr)
raise IncompatibleFrequency(msg)

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
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 7831b98

Please sign in to comment.