Skip to content

Commit a02a5c4

Browse files
authored
CLN: remove no-op BlockManager.downcast (#44198)
1 parent 457ce08 commit a02a5c4

File tree

5 files changed

+3
-27
lines changed

5 files changed

+3
-27
lines changed

pandas/core/generic.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6359,9 +6359,6 @@ def fillna(
63596359
raise NotImplementedError()
63606360
result = self.T.fillna(method=method, limit=limit).T
63616361

6362-
# need to downcast here because of all of the transposes
6363-
result._mgr = result._mgr.downcast()
6364-
63656362
return result
63666363

63676364
new_data = self._mgr.interpolate(
@@ -6415,9 +6412,6 @@ def fillna(
64156412

64166413
result = self.T.fillna(value=value, limit=limit).T
64176414

6418-
# need to downcast here because of all of the transposes
6419-
result._mgr = result._mgr.downcast()
6420-
64216415
new_data = result
64226416
else:
64236417

pandas/core/internals/array_manager.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,6 @@ def fillna(self: T, value, limit, inplace: bool, downcast) -> T:
388388
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
389389
)
390390

391-
def downcast(self: T) -> T:
392-
return self.apply_with_block("downcast")
393-
394391
def astype(self: T, dtype, copy: bool = False, errors: str = "raise") -> T:
395392
return self.apply(astype_array_safe, dtype=dtype, copy=copy, errors=errors)
396393

pandas/core/internals/blocks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,9 @@ def _maybe_downcast(self, blocks: list[Block], downcast=None) -> list[Block]:
511511

512512
# no need to downcast our float
513513
# unless indicated
514-
if downcast is None and self.dtype.kind in ["f", "m", "M"]:
515-
# TODO: complex? more generally, self._can_hold_na?
514+
if downcast is None and self.dtype.kind in ["f", "c", "m", "M"]:
515+
# passing "infer" to maybe_downcast_to_dtype (via self.downcast)
516+
# would be a no-op, so we can short-circuit
516517
return blocks
517518

518519
return extend_blocks([b.downcast(downcast) for b in blocks])

pandas/core/internals/managers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,6 @@ def fillna(self: T, value, limit, inplace: bool, downcast) -> T:
394394
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
395395
)
396396

397-
def downcast(self: T) -> T:
398-
return self.apply("downcast")
399-
400397
def astype(self: T, dtype, copy: bool = False, errors: str = "raise") -> T:
401398
return self.apply("astype", dtype=dtype, copy=copy, errors=errors)
402399

pandas/tests/generic/test_generic.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,6 @@ def test_nonzero(self):
164164
with pytest.raises(ValueError, match=msg):
165165
not obj1
166166

167-
def test_downcast(self):
168-
# test close downcasting
169-
170-
o = self._construct(shape=4, value=9, dtype=np.int64)
171-
result = o.copy()
172-
result._mgr = o._mgr.downcast()
173-
self._compare(result, o)
174-
175-
o = self._construct(shape=4, value=9.5)
176-
result = o.copy()
177-
result._mgr = o._mgr.downcast()
178-
self._compare(result, o)
179-
180167
def test_constructor_compound_dtypes(self):
181168
# see gh-5191
182169
# Compound dtypes should raise NotImplementedError.

0 commit comments

Comments
 (0)