Skip to content

Commit 5db5e4b

Browse files
committed
Fix where kludge
1 parent 814d001 commit 5db5e4b

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ def _from_sequence_of_strings(
407407
mask = strings.is_null()
408408
scalars = pa.array(scalars, mask=np.array(mask), type=pa_type)
409409
# TODO: could we just do strings.cast(pa_type)?
410+
elif isinstance(strings, (pa.Array, pa.ChunkedArray)):
411+
scalars = strings.cast(pa_type)
410412
elif mask is not None:
411413
scalars = pa.array(scalars, mask=mask.view(bool), type=pa_type)
412414

pandas/core/generic.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10089,23 +10089,6 @@ def where(
1008910089
stacklevel=2,
1009010090
)
1009110091

10092-
if other is lib.no_default:
10093-
if self.ndim == 1:
10094-
if isinstance(self.dtype, ExtensionDtype):
10095-
other = self.dtype.na_value
10096-
else:
10097-
other = np.nan
10098-
else:
10099-
if self._mgr.nblocks == 1 and isinstance(
10100-
self._mgr.blocks[0].values.dtype, ExtensionDtype
10101-
):
10102-
# FIXME: checking this is kludgy!
10103-
other = self._mgr.blocks[0].values.dtype.na_value
10104-
else:
10105-
# FIXME: the same problem we had with Series will now
10106-
# show up column-by-column!
10107-
other = np.nan
10108-
1010910092
other = common.apply_if_callable(other, self)
1011010093
return self._where(cond, other, inplace=inplace, axis=axis, level=level)
1011110094

pandas/tests/extension/test_arrow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,11 @@ def test_to_numpy_int_with_na():
15621562
data = [1, None]
15631563
arr = pd.array(data, dtype="int64[pyarrow]")
15641564
result = arr.to_numpy()
1565-
expected = np.array([1, np.nan])
1566-
assert isinstance(result[0], float)
1565+
if using_pyarrow_strict_nans():
1566+
expected = np.array([1, pd.NA], dtype=object)
1567+
else:
1568+
expected = np.array([1, np.nan])
1569+
assert isinstance(result[0], float)
15671570
tm.assert_numpy_array_equal(result, expected)
15681571

15691572

0 commit comments

Comments
 (0)