Skip to content

Commit 055e337

Browse files
authored
merge NonConsolidateableMixin into ExtensionArray (#32714)
1 parent 2b958d4 commit 055e337

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

pandas/core/internals/blocks.py

+18-25
Original file line numberDiff line numberDiff line change
@@ -1598,12 +1598,22 @@ def _replace_coerce(
15981598
return self
15991599

16001600

1601-
class NonConsolidatableMixIn:
1602-
""" hold methods for the nonconsolidatable blocks """
1601+
class ExtensionBlock(Block):
1602+
"""
1603+
Block for holding extension types.
1604+
1605+
Notes
1606+
-----
1607+
This holds all 3rd-party extension array types. It's also the immediate
1608+
parent class for our internal extension types' blocks, CategoricalBlock.
1609+
1610+
ExtensionArrays are limited to 1-D.
1611+
"""
16031612

16041613
_can_consolidate = False
16051614
_verify_integrity = False
16061615
_validate_ndim = False
1616+
is_extension = True
16071617

16081618
def __init__(self, values, placement, ndim=None):
16091619
"""
@@ -1614,6 +1624,8 @@ def __init__(self, values, placement, ndim=None):
16141624
This will call continue to call __init__ for the other base
16151625
classes mixed in with this Mixin.
16161626
"""
1627+
values = self._maybe_coerce_values(values)
1628+
16171629
# Placement must be converted to BlockPlacement so that we can check
16181630
# its length
16191631
if not isinstance(placement, libinternals.BlockPlacement):
@@ -1627,6 +1639,10 @@ def __init__(self, values, placement, ndim=None):
16271639
ndim = 2
16281640
super().__init__(values, placement, ndim=ndim)
16291641

1642+
if self.ndim == 2 and len(self.mgr_locs) != 1:
1643+
# TODO(2DEA): check unnecessary with 2D EAs
1644+
raise AssertionError("block.size != values.size")
1645+
16301646
@property
16311647
def shape(self):
16321648
if self.ndim == 1:
@@ -1722,29 +1738,6 @@ def _get_unstack_items(self, unstacker, new_columns):
17221738
mask = mask.any(0)
17231739
return new_placement, new_values, mask
17241740

1725-
1726-
class ExtensionBlock(NonConsolidatableMixIn, Block):
1727-
"""
1728-
Block for holding extension types.
1729-
1730-
Notes
1731-
-----
1732-
This holds all 3rd-party extension array types. It's also the immediate
1733-
parent class for our internal extension types' blocks, CategoricalBlock.
1734-
1735-
ExtensionArrays are limited to 1-D.
1736-
"""
1737-
1738-
is_extension = True
1739-
1740-
def __init__(self, values, placement, ndim=None):
1741-
values = self._maybe_coerce_values(values)
1742-
super().__init__(values, placement, ndim)
1743-
1744-
if self.ndim == 2 and len(self.mgr_locs) != 1:
1745-
# TODO(2DEA): check unnecessary with 2D EAs
1746-
raise AssertionError("block.size != values.size")
1747-
17481741
def _maybe_coerce_values(self, values):
17491742
"""
17501743
Unbox to an extension array.

pandas/tests/extension/test_external_block.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
import pandas as pd
55
from pandas.core.internals import BlockManager, SingleBlockManager
6-
from pandas.core.internals.blocks import Block, NonConsolidatableMixIn
6+
from pandas.core.internals.blocks import ExtensionBlock
77

88

9-
class CustomBlock(NonConsolidatableMixIn, Block):
9+
class CustomBlock(ExtensionBlock):
1010

1111
_holder = np.ndarray
12+
_can_hold_na = False
1213

1314
def concat_same_type(self, to_concat, placement=None):
1415
"""

0 commit comments

Comments
 (0)