Skip to content

Commit 90a405d

Browse files
committed
Fix where kludge
1 parent c38d7eb commit 90a405d

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
@@ -10032,23 +10032,6 @@ def where(
1003210032
stacklevel=2,
1003310033
)
1003410034

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

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)