Skip to content

Commit 2ea3fc8

Browse files
Backport PR #36675 on branch 1.1.x (REGR: Series.loc with a MultiIndex containing Timestamp raises InvalidIndexError) (#36818)
Co-authored-by: Simon Hawkins <[email protected]>
1 parent 5ad5d9e commit 2ea3fc8

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-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
@@ -1064,7 +1064,7 @@ def _handle_lowerdim_multi_index_axis0(self, tup: Tuple):
10641064
try:
10651065
# fast path for series or for tup devoid of slices
10661066
return self._get_label(tup, axis=axis)
1067-
except TypeError:
1067+
except (TypeError, InvalidIndexError):
10681068
# slices are unhashable
10691069
pass
10701070
except KeyError as ek:

pandas/tests/indexing/multiindex/test_loc.py

+10
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,16 @@ 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, index=pd.MultiIndex.from_tuples([("a", date)], names=["a", "b"]), name="c",
501+
)
502+
result = ser.loc[:, [date]]
503+
tm.assert_series_equal(result, ser)
504+
505+
496506
def test_loc_with_mi_indexer():
497507
# https://github.com/pandas-dev/pandas/issues/35351
498508
df = DataFrame(

0 commit comments

Comments
 (0)