Skip to content

Commit 3ba7e49

Browse files
mroeschkeim-vinicius
authored and
im-vinicius
committed
BUG: Indexing a timestamp ArrowDtype Index (pandas-dev#53652)
* BUG: Indexing a timestamp ArrowDtype Index * more explicit check
1 parent 56f626d commit 3ba7e49

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

doc/source/whatsnew/v2.0.3.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Bug fixes
2828
- Bug in :func:`read_csv` when defining ``dtype`` with ``bool[pyarrow]`` for the ``"c"`` and ``"python"`` engines (:issue:`53390`)
2929
- Bug in :meth:`Series.str.split` and :meth:`Series.str.rsplit` with ``expand=True`` for :class:`ArrowDtype` with ``pyarrow.string`` (:issue:`53532`)
3030
- Bug in indexing methods (e.g. :meth:`DataFrame.__getitem__`) where taking the entire :class:`DataFrame`/:class:`Series` would raise an ``OverflowError`` when Copy on Write was enabled and the length of the array was over the maximum size a 32-bit integer can hold (:issue:`53616`)
31-
-
31+
- Bug when indexing a :class:`DataFrame` or :class:`Series` with an :class:`Index` with a timestamp :class:`ArrowDtype` would raise an ``AttributeError`` (:issue:`53644`)
3232

3333
.. ---------------------------------------------------------------------------
3434
.. _whatsnew_203.other:

pandas/core/indexes/base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6055,7 +6055,9 @@ def _get_indexer_strict(self, key, axis_name: str_t) -> tuple[Index, np.ndarray]
60556055
if isinstance(key, Index):
60566056
# GH 42790 - Preserve name from an Index
60576057
keyarr.name = key.name
6058-
if keyarr.dtype.kind in "mM":
6058+
if lib.is_np_dtype(keyarr.dtype, "mM") or isinstance(
6059+
keyarr.dtype, DatetimeTZDtype
6060+
):
60596061
# DTI/TDI.take can infer a freq in some cases when we dont want one
60606062
if isinstance(key, list) or (
60616063
isinstance(key, type(self))

pandas/tests/indexing/test_datetime.py

+18
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,21 @@ def test_getitem_str_slice_millisecond_resolution(self, frame_or_series):
168168
],
169169
)
170170
tm.assert_equal(result, expected)
171+
172+
def test_getitem_pyarrow_index(self, frame_or_series):
173+
# GH 53644
174+
pytest.importorskip("pyarrow")
175+
obj = frame_or_series(
176+
range(5),
177+
index=date_range("2020", freq="D", periods=5).astype(
178+
"timestamp[us][pyarrow]"
179+
),
180+
)
181+
result = obj.loc[obj.index[:-3]]
182+
expected = frame_or_series(
183+
range(2),
184+
index=date_range("2020", freq="D", periods=2).astype(
185+
"timestamp[us][pyarrow]"
186+
),
187+
)
188+
tm.assert_equal(result, expected)

0 commit comments

Comments
 (0)