Skip to content

Commit 6aba0e1

Browse files
committed
BUG: indexing empty pyarrow backed object returning corrupt object
1 parent 85f372b commit 6aba0e1

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,7 @@ Indexing
12471247
- Bug in :meth:`DataFrame.compare` does not recognize differences when comparing ``NA`` with value in nullable dtypes (:issue:`48939`)
12481248
- Bug in :meth:`Series.rename` with :class:`MultiIndex` losing extension array dtypes (:issue:`21055`)
12491249
- Bug in :meth:`DataFrame.isetitem` coercing extension array dtypes in :class:`DataFrame` to object (:issue:`49922`)
1250+
- Bug in :meth:`Series.__getitem__` returning corrupt object when selecting from an empty pyarrow backed object (:issue:`51734`)
12501251
- Bug in :class:`BusinessHour` would cause creation of :class:`DatetimeIndex` to fail when no opening hour was included in the index (:issue:`49835`)
12511252

12521253
Missing

pandas/_testing/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
else:
253253
FLOAT_PYARROW_DTYPES_STR_REPR = []
254254
ALL_INT_PYARROW_DTYPES_STR_REPR = []
255+
ALL_PYARROW_DTYPES = []
255256

256257

257258
EMPTY_STRING_PATTERN = re.compile("^$")

pandas/core/arrays/arrow/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def __getitem__(self, item: PositionalIndexer):
349349
pa_dtype = pa.string()
350350
else:
351351
pa_dtype = self._dtype.pyarrow_dtype
352-
return type(self)(pa.chunked_array([], type=pa_dtype))
352+
return type(self)(pa.array([], type=pa_dtype, from_pandas=True))
353353
elif is_integer_dtype(item.dtype):
354354
return self.take(item)
355355
elif is_bool_dtype(item.dtype):

pandas/tests/reshape/concat/test_series.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33

44
from pandas import (
5+
ArrowDtype,
56
DataFrame,
67
DatetimeIndex,
78
Index,
@@ -151,3 +152,11 @@ def test_concat_series_length_one_reversed(self, frame_or_series):
151152
obj = frame_or_series([100])
152153
result = concat([obj.iloc[::-1]])
153154
tm.assert_equal(result, obj)
155+
156+
@pytest.mark.parametrize("dtype", tm.ALL_PYARROW_DTYPES)
157+
def test_concat_empty_arrow_backed_series(self, dtype):
158+
# GH#51734
159+
ser = Series([], dtype=ArrowDtype(dtype))
160+
expected = ser.copy()
161+
result = concat([ser[np.array([], dtype=np.bool_)]])
162+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)