Skip to content

Commit 5239a4b

Browse files
[ArrayManager] Enable downcast in fillna / enable where indexing tests (pandas-dev#39697)
1 parent 431f5d8 commit 5239a4b

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ jobs:
154154
source activate pandas-dev
155155
pytest pandas/tests/frame/methods --array-manager
156156
157-
# indexing iset related (temporary since other tests don't pass yet)
157+
# indexing subset (temporary since other tests don't pass yet)
158+
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean --array-manager
159+
pytest pandas/tests/frame/indexing/test_where.py --array-manager
158160
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_multi_index --array-manager
159161
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_listlike_indexer_duplicate_columns --array-manager
160162
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_astype_assignment_with_dups --array-manager

pandas/core/internals/array_manager.py

+5-24
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99

10-
from pandas._libs import algos as libalgos, lib
10+
from pandas._libs import lib
1111
from pandas._typing import ArrayLike, DtypeObj, Hashable
1212
from pandas.util._validators import validate_bool_kwarg
1313

@@ -377,28 +377,9 @@ def shift(self, periods: int, axis: int, fill_value) -> ArrayManager:
377377
)
378378

379379
def fillna(self, value, limit, inplace: bool, downcast) -> ArrayManager:
380-
# TODO implement downcast
381-
inplace = validate_bool_kwarg(inplace, "inplace")
382-
383-
def array_fillna(array, value, limit, inplace):
384-
385-
mask = isna(array)
386-
if limit is not None:
387-
limit = libalgos.validate_limit(None, limit=limit)
388-
mask[mask.cumsum() > limit] = False
389-
390-
# TODO could optimize for arrays that cannot hold NAs
391-
# (like _can_hold_na on Blocks)
392-
if not inplace:
393-
array = array.copy()
394-
395-
# np.putmask(array, mask, value)
396-
if np.any(mask):
397-
# TODO allow invalid value if there is nothing to fill?
398-
array[mask] = value
399-
return array
400-
401-
return self.apply(array_fillna, value=value, limit=limit, inplace=inplace)
380+
return self.apply_with_block(
381+
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
382+
)
402383

403384
def downcast(self) -> ArrayManager:
404385
return self.apply_with_block("downcast")
@@ -454,7 +435,7 @@ def is_mixed_type(self) -> bool:
454435

455436
@property
456437
def is_numeric_mixed_type(self) -> bool:
457-
return False
438+
return all(is_numeric_dtype(t) for t in self.get_dtypes())
458439

459440
@property
460441
def any_extension_types(self) -> bool:

pandas/tests/frame/indexing/test_where.py

+1
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def test_where_axis(self):
499499
assert return_value is None
500500
tm.assert_frame_equal(result, expected)
501501

502+
def test_where_axis_multiple_dtypes(self):
502503
# Multiple dtypes (=> multiple Blocks)
503504
df = pd.concat(
504505
[

0 commit comments

Comments
 (0)