@@ -124,14 +124,28 @@ def _simple_new(
124
124
def __init__ (self , values , placement , ndim = None ):
125
125
self .ndim = self ._check_ndim (values , ndim )
126
126
self .mgr_locs = placement
127
- self .values = values
127
+ self .values = self . _maybe_coerce_values ( values )
128
128
129
129
if self ._validate_ndim and self .ndim and len (self .mgr_locs ) != len (self .values ):
130
130
raise ValueError (
131
131
f"Wrong number of items passed { len (self .values )} , "
132
132
f"placement implies { len (self .mgr_locs )} "
133
133
)
134
134
135
+ def _maybe_coerce_values (self , values ):
136
+ """
137
+ Ensure we have correctly-typed values.
138
+
139
+ Parameters
140
+ ----------
141
+ values : np.ndarray, ExtensionArray, Index
142
+
143
+ Returns
144
+ -------
145
+ np.ndarray or ExtensionArray
146
+ """
147
+ return values
148
+
135
149
def _check_ndim (self , values , ndim ):
136
150
"""
137
151
ndim inference and validation.
@@ -1614,7 +1628,6 @@ def __init__(self, values, placement, ndim=None):
1614
1628
This will call continue to call __init__ for the other base
1615
1629
classes mixed in with this Mixin.
1616
1630
"""
1617
- values = self ._maybe_coerce_values (values )
1618
1631
1619
1632
# Placement must be converted to BlockPlacement so that we can check
1620
1633
# its length
@@ -2109,10 +2122,6 @@ class DatetimeBlock(DatetimeLikeBlockMixin, Block):
2109
2122
__slots__ = ()
2110
2123
is_datetime = True
2111
2124
2112
- def __init__ (self , values , placement , ndim = None ):
2113
- values = self ._maybe_coerce_values (values )
2114
- super ().__init__ (values , placement = placement , ndim = ndim )
2115
-
2116
2125
@property
2117
2126
def _can_hold_na (self ):
2118
2127
return True
@@ -2366,14 +2375,14 @@ class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
2366
2375
is_numeric = False
2367
2376
fill_value = np .timedelta64 ("NaT" , "ns" )
2368
2377
2369
- def __init__ (self , values , placement , ndim = None ):
2378
+ def _maybe_coerce_values (self , values ):
2370
2379
if values .dtype != TD64NS_DTYPE :
2371
2380
# e.g. non-nano or int64
2372
2381
values = TimedeltaArray ._from_sequence (values )._data
2373
2382
if isinstance (values , TimedeltaArray ):
2374
2383
values = values ._data
2375
2384
assert isinstance (values , np .ndarray ), type (values )
2376
- super (). __init__ ( values , placement = placement , ndim = ndim )
2385
+ return values
2377
2386
2378
2387
@property
2379
2388
def _holder (self ):
@@ -2426,11 +2435,10 @@ class ObjectBlock(Block):
2426
2435
is_object = True
2427
2436
_can_hold_na = True
2428
2437
2429
- def __init__ (self , values , placement = None , ndim = 2 ):
2438
+ def _maybe_coerce_values (self , values ):
2430
2439
if issubclass (values .dtype .type , str ):
2431
2440
values = np .array (values , dtype = object )
2432
-
2433
- super ().__init__ (values , ndim = ndim , placement = placement )
2441
+ return values
2434
2442
2435
2443
@property
2436
2444
def is_bool (self ):
0 commit comments