Skip to content

Commit d6fe5f0

Browse files
authored
CLN: remove FloatBlock, share _can_hold_na (#40526)
1 parent a68d28c commit d6fe5f0

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

pandas/core/internals/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
DatetimeBlock,
1313
DatetimeTZBlock,
1414
ExtensionBlock,
15-
FloatBlock,
1615
NumericBlock,
1716
ObjectBlock,
1817
TimeDeltaBlock,
@@ -31,7 +30,6 @@
3130
"DatetimeBlock",
3231
"DatetimeTZBlock",
3332
"ExtensionBlock",
34-
"FloatBlock",
3533
"ObjectBlock",
3634
"TimeDeltaBlock",
3735
"make_block",

pandas/core/internals/blocks.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ class Block(PandasObject):
157157
is_bool = False
158158
is_object = False
159159
is_extension = False
160-
_can_hold_na = False
161160
_can_consolidate = True
162161
_validate_ndim = True
163162

@@ -212,6 +211,17 @@ def is_view(self) -> bool:
212211
values = cast(np.ndarray, values)
213212
return values.base is not None
214213

214+
@final
215+
@property
216+
def _can_hold_na(self) -> bool:
217+
"""
218+
Can we store NA values in this Block?
219+
"""
220+
values = self.values
221+
if isinstance(values, np.ndarray):
222+
return values.dtype.kind not in ["b", "i", "u"]
223+
return values._can_hold_na
224+
215225
@final
216226
@property
217227
def is_categorical(self) -> bool:
@@ -1504,11 +1514,6 @@ def _holder(self):
15041514
# For extension blocks, the holder is values-dependent.
15051515
return type(self.values)
15061516

1507-
@property
1508-
def _can_hold_na(self):
1509-
# The default ExtensionArray._can_hold_na is True
1510-
return self._holder._can_hold_na
1511-
15121517
@property
15131518
def is_view(self) -> bool:
15141519
"""Extension arrays are never treated as views."""
@@ -1787,19 +1792,11 @@ def _can_hold_element(self, element: Any) -> bool:
17871792
# "Union[dtype[Any], ExtensionDtype]"; expected "dtype[Any]"
17881793
return can_hold_element(self.dtype, element) # type: ignore[arg-type]
17891794

1790-
@property
1791-
def _can_hold_na(self):
1792-
return self.dtype.kind not in ["b", "i", "u"]
1793-
17941795
@property
17951796
def is_bool(self):
17961797
return self.dtype.kind == "b"
17971798

17981799

1799-
class FloatBlock(NumericBlock):
1800-
__slots__ = ()
1801-
1802-
18031800
class NDArrayBackedExtensionBlock(HybridMixin, Block):
18041801
"""
18051802
Block backed by an NDArrayBackedExtensionArray
@@ -1909,7 +1906,6 @@ class DatetimeLikeBlockMixin(NDArrayBackedExtensionBlock):
19091906
"""Mixin class for DatetimeBlock, DatetimeTZBlock, and TimedeltaBlock."""
19101907

19111908
is_numeric = False
1912-
_can_hold_na = True
19131909

19141910
def array_values(self):
19151911
return ensure_wrapped_if_datetimelike(self.values)
@@ -1938,7 +1934,6 @@ class DatetimeTZBlock(ExtensionBlock, DatetimeBlock):
19381934

19391935
__slots__ = ()
19401936
is_extension = True
1941-
_can_hold_na = True
19421937
is_numeric = False
19431938

19441939
internal_values = Block.internal_values
@@ -1970,7 +1965,6 @@ class TimeDeltaBlock(DatetimeLikeBlockMixin):
19701965
class ObjectBlock(Block):
19711966
__slots__ = ()
19721967
is_object = True
1973-
_can_hold_na = True
19741968

19751969
values: np.ndarray
19761970

@@ -2109,9 +2103,7 @@ def get_block_type(values, dtype: Optional[Dtype] = None):
21092103
cls = DatetimeBlock
21102104
elif kind == "m":
21112105
cls = TimeDeltaBlock
2112-
elif kind == "f":
2113-
cls = FloatBlock
2114-
elif kind in ["c", "i", "u", "b"]:
2106+
elif kind in ["f", "c", "i", "u", "b"]:
21152107
cls = NumericBlock
21162108
else:
21172109
cls = ObjectBlock

pandas/core/internals/managers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1839,13 +1839,9 @@ def _form_blocks(
18391839
items_dict[block_type.__name__].append((i, v))
18401840

18411841
blocks: List[Block] = []
1842-
if len(items_dict["FloatBlock"]):
1843-
float_blocks = _multi_blockify(items_dict["FloatBlock"])
1844-
blocks.extend(float_blocks)
1845-
18461842
if len(items_dict["NumericBlock"]):
1847-
complex_blocks = _multi_blockify(items_dict["NumericBlock"])
1848-
blocks.extend(complex_blocks)
1843+
numeric_blocks = _multi_blockify(items_dict["NumericBlock"])
1844+
blocks.extend(numeric_blocks)
18491845

18501846
if len(items_dict["TimeDeltaBlock"]):
18511847
timedelta_blocks = _multi_blockify(items_dict["TimeDeltaBlock"])

pandas/tests/extension/test_external_block.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
class CustomBlock(ExtensionBlock):
1515

1616
_holder = np.ndarray
17-
_can_hold_na = False
17+
# error: Cannot override final attribute "_can_hold_na"
18+
# (previously declared in base class "Block")
19+
_can_hold_na = False # type: ignore[misc]
1820

1921

2022
@pytest.fixture

pandas/tests/internals/test_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def test_namespace():
3030
"DatetimeBlock",
3131
"DatetimeTZBlock",
3232
"ExtensionBlock",
33-
"FloatBlock",
3433
"ObjectBlock",
3534
"TimeDeltaBlock",
3635
"make_block",

0 commit comments

Comments
 (0)