Skip to content

[ArrayManager] Enable downcast in fillna / enable where indexing tests #39697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ jobs:
source activate pandas-dev
pytest pandas/tests/frame/methods --array-manager

# indexing iset related (temporary since other tests don't pass yet)
# indexing subset (temporary since other tests don't pass yet)
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean --array-manager
pytest pandas/tests/frame/indexing/test_where.py --array-manager
pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_multi_index --array-manager
pytest pandas/tests/frame/indexing/test_setitem.py::TestDataFrameSetItem::test_setitem_listlike_indexer_duplicate_columns --array-manager
pytest pandas/tests/indexing/multiindex/test_setitem.py::TestMultiIndexSetItem::test_astype_assignment_with_dups --array-manager
Expand Down
29 changes: 5 additions & 24 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from pandas._libs import algos as libalgos, lib
from pandas._libs import lib
from pandas._typing import ArrayLike, DtypeObj, Hashable
from pandas.util._validators import validate_bool_kwarg

Expand Down Expand Up @@ -377,28 +377,9 @@ def shift(self, periods: int, axis: int, fill_value) -> ArrayManager:
)

def fillna(self, value, limit, inplace: bool, downcast) -> ArrayManager:
# TODO implement downcast
inplace = validate_bool_kwarg(inplace, "inplace")

def array_fillna(array, value, limit, inplace):

mask = isna(array)
if limit is not None:
limit = libalgos.validate_limit(None, limit=limit)
mask[mask.cumsum() > limit] = False

# TODO could optimize for arrays that cannot hold NAs
# (like _can_hold_na on Blocks)
if not inplace:
array = array.copy()

# np.putmask(array, mask, value)
if np.any(mask):
# TODO allow invalid value if there is nothing to fill?
array[mask] = value
return array

return self.apply(array_fillna, value=value, limit=limit, inplace=inplace)
return self.apply_with_block(
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
)

def downcast(self) -> ArrayManager:
return self.apply_with_block("downcast")
Expand Down Expand Up @@ -454,7 +435,7 @@ def is_mixed_type(self) -> bool:

@property
def is_numeric_mixed_type(self) -> bool:
return False
return all(is_numeric_dtype(t) for t in self.get_dtypes())

@property
def any_extension_types(self) -> bool:
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/frame/indexing/test_where.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ def test_where_axis(self):
assert return_value is None
tm.assert_frame_equal(result, expected)

def test_where_axis_multiple_dtypes(self):
# Multiple dtypes (=> multiple Blocks)
df = pd.concat(
[
Expand Down