Skip to content

Commit 469ad52

Browse files
REGR: Series.loc with a MultiIndex containing Timestamp raises InvalidIndexError (#36675)
1 parent fbb490c commit 469ad52

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v1.1.3.rst

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Fixed regressions
3737
- Fixed regression in modulo of :class:`Index`, :class:`Series` and :class:`DataFrame` using ``numexpr`` using C not Python semantics (:issue:`36047`, :issue:`36526`)
3838
- Fixed regression in :meth:`read_excel` with ``engine="odf"`` caused ``UnboundLocalError`` in some cases where cells had nested child nodes (:issue:`36122`, :issue:`35802`)
3939
- Fixed regression in :meth:`DataFrame.replace` inconsistent replace when using a float in the replace method (:issue:`35376`)
40+
- Fixed regression in :meth:`Series.loc` on a :class:`Series` with a :class:`MultiIndex` containing :class:`Timestamp` raising ``InvalidIndexError`` (:issue:`35858`)
4041
- Fixed regression in :class:`DataFrame` and :class:`Series` comparisons between numeric arrays and strings (:issue:`35700`, :issue:`36377`)
4142
- Fixed regression in :meth:`DataFrame.apply` with ``raw=True`` and user-function returning string (:issue:`35940`)
4243
- Fixed regression when setting empty :class:`DataFrame` column to a :class:`Series` in preserving name of index in frame (:issue:`36527`)

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
10761076
try:
10771077
# fast path for series or for tup devoid of slices
10781078
return self._get_label(tup, axis=axis)
1079-
except TypeError:
1079+
except (TypeError, InvalidIndexError):
10801080
# slices are unhashable
10811081
pass
10821082
except KeyError as ek:

pandas/tests/indexing/multiindex/test_loc.py

+12
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,18 @@ def test_loc_datetime_mask_slicing():
493493
tm.assert_series_equal(result, expected)
494494

495495

496+
def test_loc_datetime_series_tuple_slicing():
497+
# https://github.com/pandas-dev/pandas/issues/35858
498+
date = pd.Timestamp("2000")
499+
ser = pd.Series(
500+
1,
501+
index=pd.MultiIndex.from_tuples([("a", date)], names=["a", "b"]),
502+
name="c",
503+
)
504+
result = ser.loc[:, [date]]
505+
tm.assert_series_equal(result, ser)
506+
507+
496508
def test_loc_with_mi_indexer():
497509
# https://github.com/pandas-dev/pandas/issues/35351
498510
df = DataFrame(

0 commit comments

Comments
 (0)