Skip to content

Commit 51306ab

Browse files
committed
Fix where kludge
1 parent 45e1e7e commit 51306ab

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
@@ -10079,23 +10079,6 @@ def where(
1007910079
stacklevel=2,
1008010080
)
1008110081

10082-
if other is lib.no_default:
10083-
if self.ndim == 1:
10084-
if isinstance(self.dtype, ExtensionDtype):
10085-
other = self.dtype.na_value
10086-
else:
10087-
other = np.nan
10088-
else:
10089-
if self._mgr.nblocks == 1 and isinstance(
10090-
self._mgr.blocks[0].values.dtype, ExtensionDtype
10091-
):
10092-
# FIXME: checking this is kludgy!
10093-
other = self._mgr.blocks[0].values.dtype.na_value
10094-
else:
10095-
# FIXME: the same problem we had with Series will now
10096-
# show up column-by-column!
10097-
other = np.nan
10098-
1009910082
other = common.apply_if_callable(other, self)
1010010083
return self._where(cond, other, inplace=inplace, axis=axis, level=level)
1010110084

pandas/tests/extension/test_arrow.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,8 +1569,11 @@ def test_to_numpy_int_with_na():
15691569
data = [1, None]
15701570
arr = pd.array(data, dtype="int64[pyarrow]")
15711571
result = arr.to_numpy()
1572-
expected = np.array([1, np.nan])
1573-
assert isinstance(result[0], float)
1572+
if using_pyarrow_strict_nans():
1573+
expected = np.array([1, pd.NA], dtype=object)
1574+
else:
1575+
expected = np.array([1, np.nan])
1576+
assert isinstance(result[0], float)
15741577
tm.assert_numpy_array_equal(result, expected)
15751578

15761579

0 commit comments

Comments
 (0)