Skip to content

CLN: remove no-op BlockManager.downcast #44198

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
merged 3 commits into from
Oct 27, 2021
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
6 changes: 0 additions & 6 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6359,9 +6359,6 @@ def fillna(
raise NotImplementedError()
result = self.T.fillna(method=method, limit=limit).T

# need to downcast here because of all of the transposes
result._mgr = result._mgr.downcast()

return result

new_data = self._mgr.interpolate(
Expand Down Expand Up @@ -6415,9 +6412,6 @@ def fillna(

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

# need to downcast here because of all of the transposes
result._mgr = result._mgr.downcast()

new_data = result
else:

Expand Down
3 changes: 0 additions & 3 deletions pandas/core/internals/array_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ def fillna(self: T, value, limit, inplace: bool, downcast) -> T:
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
)

def downcast(self: T) -> T:
return self.apply_with_block("downcast")

def astype(self: T, dtype, copy: bool = False, errors: str = "raise") -> T:
return self.apply(astype_array_safe, dtype=dtype, copy=copy, errors=errors)

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,9 @@ def _maybe_downcast(self, blocks: list[Block], downcast=None) -> list[Block]:

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

return extend_blocks([b.downcast(downcast) for b in blocks])
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,6 @@ def fillna(self: T, value, limit, inplace: bool, downcast) -> T:
"fillna", value=value, limit=limit, inplace=inplace, downcast=downcast
)

def downcast(self: T) -> T:
return self.apply("downcast")

def astype(self: T, dtype, copy: bool = False, errors: str = "raise") -> T:
return self.apply("astype", dtype=dtype, copy=copy, errors=errors)

Expand Down
13 changes: 0 additions & 13 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,6 @@ def test_nonzero(self):
with pytest.raises(ValueError, match=msg):
not obj1

def test_downcast(self):
# test close downcasting

o = self._construct(shape=4, value=9, dtype=np.int64)
result = o.copy()
result._mgr = o._mgr.downcast()
self._compare(result, o)

o = self._construct(shape=4, value=9.5)
result = o.copy()
result._mgr = o._mgr.downcast()
self._compare(result, o)

def test_constructor_compound_dtypes(self):
# see gh-5191
# Compound dtypes should raise NotImplementedError.
Expand Down