Skip to content

Commit 28d12e7

Browse files
authored
REF: standardize ArrowExtensionArray in tests (#46009)
1 parent 8db43ed commit 28d12e7

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

pandas/tests/extension/arrow/arrays.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class ArrowExtensionArray(OpsMixin, ExtensionArray):
7777
_data: pa.ChunkedArray
7878

7979
@classmethod
80-
def from_scalars(cls, values):
80+
def _from_sequence(cls, values, dtype=None, copy=False):
81+
# TODO: respect dtype, copy
82+
8183
if isinstance(values, cls):
8284
# in particular for empty cases the pa.array(np.asarray(...))
8385
# does not round-trip
@@ -91,15 +93,6 @@ def from_scalars(cls, values):
9193
arr = pa.chunked_array([pa.array(np.asarray(values))])
9294
return cls(arr)
9395

94-
@classmethod
95-
def from_array(cls, arr):
96-
assert isinstance(arr, pa.Array)
97-
return cls(pa.chunked_array([arr]))
98-
99-
@classmethod
100-
def _from_sequence(cls, scalars, dtype=None, copy=False):
101-
return cls.from_scalars(scalars)
102-
10396
def __repr__(self):
10497
return f"{type(self).__name__}({repr(self._data)})"
10598

@@ -116,7 +109,7 @@ def __getitem__(self, item):
116109
return self._data.to_pandas()[item]
117110
else:
118111
vals = self._data.to_pandas()[item]
119-
return type(self).from_scalars(vals)
112+
return type(self)._from_sequence(vals)
120113

121114
def __len__(self):
122115
return len(self._data)
@@ -160,7 +153,7 @@ def nbytes(self) -> int:
160153

161154
def isna(self):
162155
nas = pd.isna(self._data.to_pandas())
163-
return type(self).from_scalars(nas)
156+
return type(self)._from_sequence(nas)
164157

165158
def take(self, indices, allow_fill=False, fill_value=None):
166159
data = self._data.to_pandas()
@@ -182,7 +175,7 @@ def _concat_same_type(cls, to_concat):
182175
return cls(arr)
183176

184177
def __invert__(self):
185-
return type(self).from_scalars(~self._data.to_pandas())
178+
return type(self)._from_sequence(~self._data.to_pandas())
186179

187180
def _reduce(self, name: str, *, skipna: bool = True, **kwargs):
188181
if skipna:

pandas/tests/extension/arrow/test_bool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def dtype():
2323
def data():
2424
values = np.random.randint(0, 2, size=100, dtype=bool)
2525
values[1] = ~values[0]
26-
return ArrowBoolArray.from_scalars(values)
26+
return ArrowBoolArray._from_sequence(values)
2727

2828

2929
@pytest.fixture
3030
def data_missing():
31-
return ArrowBoolArray.from_scalars([None, True])
31+
return ArrowBoolArray._from_sequence([None, True])
3232

3333

3434
def test_basic_equals(data):

pandas/tests/extension/arrow/test_timestamp.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ def __init__(self, values):
5151

5252
def test_constructor_extensionblock():
5353
# GH 34986
54-
pd.DataFrame(
55-
{
56-
"timestamp": ArrowTimestampUSArray.from_scalars(
57-
[None, datetime.datetime(2010, 9, 8, 7, 6, 5, 4)]
58-
)
59-
}
54+
arr = ArrowTimestampUSArray._from_sequence(
55+
[None, datetime.datetime(2010, 9, 8, 7, 6, 5, 4)]
6056
)
57+
pd.DataFrame({"timestamp": arr})

0 commit comments

Comments
 (0)