Skip to content

Commit 27989a6

Browse files
REGR: revert "CLN: _consolidate_inplace less" / fix regression in fillna() (#34407)
1 parent 94179cd commit 27989a6

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

doc/source/whatsnew/v1.1.5.rst

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Fixed regressions
2121
- Fixed regression in metadata propagation for ``groupby`` iterator (:issue:`37343`)
2222
- Fixed regression in indexing on a :class:`Series` with ``CategoricalDtype`` after unpickling (:issue:`37631`)
2323
- Fixed regression in ``df.groupby(..).rolling(..)`` with the resulting :class:`MultiIndex` when grouping by a label that is in the index (:issue:`37641`)
24+
- Fixed regression in :meth:`DataFrame.fillna` not filling ``NaN`` after other operations such as :meth:`DataFrame.pivot` (:issue:`36495`).
2425

2526
.. ---------------------------------------------------------------------------
2627

pandas/core/generic.py

+6
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,8 @@ class animal locomotion
37093709
else:
37103710
index = self.index
37113711

3712+
self._consolidate_inplace()
3713+
37123714
if isinstance(index, MultiIndex):
37133715
try:
37143716
loc, new_index = index._get_loc_level(
@@ -6327,6 +6329,8 @@ def fillna(
63276329
inplace = validate_bool_kwarg(inplace, "inplace")
63286330
value, method = validate_fillna_kwargs(value, method)
63296331

6332+
self._consolidate_inplace()
6333+
63306334
# set the default here, so functions examining the signaure
63316335
# can detect if something was set (e.g. in groupby) (GH9221)
63326336
if axis is None:
@@ -6749,6 +6753,8 @@ def replace(
67496753
if not is_bool(regex) and to_replace is not None:
67506754
raise ValueError("'to_replace' must be 'None' if 'regex' is not a bool")
67516755

6756+
self._consolidate_inplace()
6757+
67526758
if value is None:
67536759
# passing a single value that is scalar like
67546760
# when value is None (GH5319), for compat

pandas/core/internals/managers.py

+6
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ def apply(
442442
def quantile(
443443
self,
444444
axis: int = 0,
445+
consolidate: bool = True,
445446
transposed: bool = False,
446447
interpolation="linear",
447448
qs=None,
@@ -455,6 +456,8 @@ def quantile(
455456
Parameters
456457
----------
457458
axis: reduction axis, default 0
459+
consolidate: bool, default True. Join together blocks having same
460+
dtype
458461
transposed: bool, default False
459462
we are holding transposed data
460463
interpolation : type of interpolation, default 'linear'
@@ -469,6 +472,9 @@ def quantile(
469472
# simplify some of the code here and in the blocks
470473
assert self.ndim >= 2
471474

475+
if consolidate:
476+
self._consolidate_inplace()
477+
472478
def get_axe(block, qs, axes):
473479
# Because Series dispatches to DataFrame, we will always have
474480
# block.ndim == 2

pandas/tests/frame/methods/test_fillna.py

+15
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,18 @@ def test_fill_corner(self, float_frame, float_string_frame):
524524

525525
# TODO(wesm): unused?
526526
result = empty_float.fillna(value=0) # noqa
527+
528+
529+
def test_fillna_nonconsolidated_frame():
530+
# https://github.com/pandas-dev/pandas/issues/36495
531+
df = DataFrame(
532+
[
533+
[1, 1, 1, 1.0],
534+
[2, 2, 2, 2.0],
535+
[3, 3, 3, 3.0],
536+
],
537+
columns=["i1", "i2", "i3", "f1"],
538+
)
539+
df_nonconsol = df.pivot("i1", "i2")
540+
result = df_nonconsol.fillna(0)
541+
assert result.isna().sum().sum() == 0

0 commit comments

Comments
 (0)