@@ -159,10 +159,34 @@ class Block(PandasObject):
159
159
160
160
__slots__ = ()
161
161
is_numeric = False
162
- is_object = False
163
- is_extension = False
164
- _can_consolidate = True
165
- _validate_ndim = True
162
+
163
+ @final
164
+ @cache_readonly
165
+ def _validate_ndim (self ) -> bool :
166
+ """
167
+ We validate dimension for blocks that can hold 2D values, which for now
168
+ means numpy dtypes or DatetimeTZDtype.
169
+ """
170
+ dtype = self .dtype
171
+ return not isinstance (dtype , ExtensionDtype ) or isinstance (
172
+ dtype , DatetimeTZDtype
173
+ )
174
+
175
+ @final
176
+ @cache_readonly
177
+ def is_object (self ) -> bool :
178
+ return self .values .dtype == _dtype_obj
179
+
180
+ @final
181
+ @cache_readonly
182
+ def is_extension (self ) -> bool :
183
+ return not lib .is_np_dtype (self .values .dtype )
184
+
185
+ @final
186
+ @cache_readonly
187
+ def _can_consolidate (self ) -> bool :
188
+ # We _could_ consolidate for DatetimeTZDtype but don't for now.
189
+ return not self .is_extension
166
190
167
191
@final
168
192
@cache_readonly
@@ -1908,10 +1932,6 @@ class ExtensionBlock(libinternals.Block, EABackedBlock):
1908
1932
ExtensionArrays are limited to 1-D.
1909
1933
"""
1910
1934
1911
- _can_consolidate = False
1912
- _validate_ndim = False
1913
- is_extension = True
1914
-
1915
1935
values : ExtensionArray
1916
1936
1917
1937
def fillna (
@@ -2175,10 +2195,6 @@ def is_numeric(self) -> bool: # type: ignore[override]
2175
2195
2176
2196
return kind in "fciub"
2177
2197
2178
- @cache_readonly
2179
- def is_object (self ) -> bool : # type: ignore[override]
2180
- return self .values .dtype .kind == "O"
2181
-
2182
2198
2183
2199
class NumericBlock (NumpyBlock ):
2184
2200
# this Block type is kept for backwards-compatibility
@@ -2199,12 +2215,6 @@ class NDArrayBackedExtensionBlock(libinternals.NDArrayBackedBlock, EABackedBlock
2199
2215
2200
2216
values : NDArrayBackedExtensionArray
2201
2217
2202
- # error: Signature of "is_extension" incompatible with supertype "Block"
2203
- @cache_readonly
2204
- def is_extension (self ) -> bool : # type: ignore[override]
2205
- # i.e. datetime64tz, PeriodDtype
2206
- return not isinstance (self .dtype , np .dtype )
2207
-
2208
2218
@property
2209
2219
def is_view (self ) -> bool :
2210
2220
"""return a boolean if I am possibly a view"""
@@ -2242,9 +2252,6 @@ class DatetimeTZBlock(DatetimeLikeBlock):
2242
2252
values : DatetimeArray
2243
2253
2244
2254
__slots__ = ()
2245
- is_extension = True
2246
- _validate_ndim = True
2247
- _can_consolidate = False
2248
2255
2249
2256
# Don't use values_for_json from DatetimeLikeBlock since it is
2250
2257
# an invalid optimization here(drop the tz)
0 commit comments