From af0a9bcd91ab0485738afc7313960ee7db7e03a9 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 9 Feb 2021 14:12:43 +0100 Subject: [PATCH 1/2] [ArrayManager] Enable downcast in fillna / enable where indexing tests --- .github/workflows/ci.yml | 2 ++ pandas/core/internals/array_manager.py | 29 ++++------------------- pandas/tests/frame/indexing/test_where.py | 1 + 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b551e7ded0178..9cb5a3e17f527 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,3 +157,5 @@ jobs: run: | source activate pandas-dev pytest pandas/tests/frame/methods --array-manager + pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean --array-manager + pytest pandas/tests/frame/indexing/test_where.py --array-manager diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 0f677ff3180be..613e2c79b1919 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -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 @@ -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") @@ -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: diff --git a/pandas/tests/frame/indexing/test_where.py b/pandas/tests/frame/indexing/test_where.py index 2f098426efaf9..c057968c9574d 100644 --- a/pandas/tests/frame/indexing/test_where.py +++ b/pandas/tests/frame/indexing/test_where.py @@ -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( [ From dd6cd0c2500e9c6dc5197cd07b3e2a2598cd97a5 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Tue, 16 Feb 2021 08:36:20 +0100 Subject: [PATCH 2/2] fixup merge --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c6324ea8885f..c4629048deef7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,9 +154,6 @@ jobs: source activate pandas-dev pytest pandas/tests/frame/methods --array-manager - pytest pandas/tests/frame/indexing/test_indexing.py::TestDataFrameIndexing::test_setitem_boolean --array-manager - pytest pandas/tests/frame/indexing/test_where.py --array-manager - # 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