Skip to content

Commit cc8ffb3

Browse files
authored
BUG: Index.union with timestamp[s][pyarrow] (#62276)
1 parent c316081 commit cc8ffb3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,7 @@ Datetimelike
897897
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
898898
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
899899
- Bug in :meth:`DatetimeIndex.union` and :meth:`DatetimeIndex.intersection` when ``unit`` was non-nanosecond (:issue:`59036`)
900+
- Bug in :meth:`Index.union` with a ``pyarrow`` timestamp dtype incorrectly returning ``object`` dtype (:issue:`58421`)
900901
- Bug in :meth:`Series.dt.microsecond` producing incorrect results for pyarrow backed :class:`Series`. (:issue:`59154`)
901902
- Bug in :meth:`to_datetime` not respecting dayfirst if an uncommon date string was passed. (:issue:`58859`)
902903
- Bug in :meth:`to_datetime` on float array with missing values throwing ``FloatingPointError`` (:issue:`58419`)

pandas/core/indexes/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5042,9 +5042,13 @@ def _get_join_target(self) -> np.ndarray:
50425042
if isinstance(self._values, BaseMaskedArray):
50435043
# This is only used if our array is monotonic, so no NAs present
50445044
return self._values._data
5045-
elif isinstance(self._values, ArrowExtensionArray):
5045+
elif (
5046+
isinstance(self._values, ArrowExtensionArray)
5047+
and self.dtype.kind not in "mM"
5048+
):
50465049
# This is only used if our array is monotonic, so no missing values
50475050
# present
5051+
# "mM" cases will go through _get_engine_target and cast to i8
50485052
return self._values.to_numpy()
50495053

50505054
# TODO: exclude ABCRangeIndex case here as it copies

pandas/tests/indexes/test_setops.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import pytest
1111

1212
from pandas._libs import lib
13+
import pandas.util._test_decorators as td
1314

1415
from pandas.core.dtypes.cast import find_common_type
1516

@@ -973,3 +974,13 @@ def test_union_string_array(self, any_string_dtype):
973974
result = idx1.union(idx2)
974975
expected = Index(["a", "b"], dtype=any_string_dtype)
975976
tm.assert_index_equal(result, expected)
977+
978+
@td.skip_if_no("pyarrow")
979+
def test_union_pyarrow_timestamp(self):
980+
# GH#58421
981+
left = Index(["2020-01-01"], dtype="timestamp[s][pyarrow]")
982+
right = Index(["2020-01-02"], dtype="timestamp[s][pyarrow]")
983+
984+
res = left.union(right)
985+
expected = Index(["2020-01-01", "2020-01-02"], dtype=left.dtype)
986+
tm.assert_index_equal(res, expected)

0 commit comments

Comments
 (0)