Skip to content

Commit a340203

Browse files
committed
Fix where kludge
1 parent 083f705 commit a340203

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
@@ -405,6 +405,8 @@ def _from_sequence_of_strings(
405405
mask = strings.is_null()
406406
scalars = pa.array(scalars, mask=np.array(mask), type=pa_type)
407407
# TODO: could we just do strings.cast(pa_type)?
408+
elif isinstance(strings, (pa.Array, pa.ChunkedArray)):
409+
scalars = strings.cast(pa_type)
408410
elif mask is not None:
409411
scalars = pa.array(scalars, mask=mask.view(bool), type=pa_type)
410412

pandas/core/generic.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10031,23 +10031,6 @@ def where(
1003110031
stacklevel=2,
1003210032
)
1003310033

10034-
if other is lib.no_default:
10035-
if self.ndim == 1:
10036-
if isinstance(self.dtype, ExtensionDtype):
10037-
other = self.dtype.na_value
10038-
else:
10039-
other = np.nan
10040-
else:
10041-
if self._mgr.nblocks == 1 and isinstance(
10042-
self._mgr.blocks[0].values.dtype, ExtensionDtype
10043-
):
10044-
# FIXME: checking this is kludgy!
10045-
other = self._mgr.blocks[0].values.dtype.na_value
10046-
else:
10047-
# FIXME: the same problem we had with Series will now
10048-
# show up column-by-column!
10049-
other = np.nan
10050-
1005110034
other = common.apply_if_callable(other, self)
1005210035
return self._where(cond, other, inplace=inplace, axis=axis, level=level)
1005310036

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)