66
66
)
67
67
68
68
import pandas .core .algorithms as algos
69
- from pandas .core .arrays import Categorical , DatetimeArray , PandasDtype , TimedeltaArray
69
+ from pandas .core .arrays import (
70
+ Categorical ,
71
+ DatetimeArray ,
72
+ ExtensionArray ,
73
+ PandasArray ,
74
+ PandasDtype ,
75
+ TimedeltaArray ,
76
+ )
70
77
from pandas .core .base import PandasObject
71
78
import pandas .core .common as com
72
79
from pandas .core .construction import extract_array
@@ -195,6 +202,7 @@ def is_categorical_astype(self, dtype):
195
202
def external_values (self ):
196
203
"""
197
204
The array that Series.values returns (public attribute).
205
+
198
206
This has some historical constraints, and is overridden in block
199
207
subclasses to return the correct array (e.g. period returns
200
208
object ndarray and datetimetz a datetime64[ns] ndarray instead of
@@ -208,6 +216,12 @@ def internal_values(self):
208
216
"""
209
217
return self .values
210
218
219
+ def array_values (self ) -> ExtensionArray :
220
+ """
221
+ The array that Series.array returns. Always an ExtensionArray.
222
+ """
223
+ return PandasArray (self .values )
224
+
211
225
def get_values (self , dtype = None ):
212
226
"""
213
227
return an internal format, currently just the ndarray
@@ -1780,6 +1794,9 @@ def get_values(self, dtype=None):
1780
1794
values = values .reshape ((1 ,) + values .shape )
1781
1795
return values
1782
1796
1797
+ def array_values (self ) -> ExtensionArray :
1798
+ return self .values
1799
+
1783
1800
def to_dense (self ):
1784
1801
return np .asarray (self .values )
1785
1802
@@ -2243,6 +2260,9 @@ def set(self, locs, values):
2243
2260
def external_values (self ):
2244
2261
return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
2245
2262
2263
+ def array_values (self ) -> ExtensionArray :
2264
+ return DatetimeArray ._simple_new (self .values )
2265
+
2246
2266
2247
2267
class DatetimeTZBlock (ExtensionBlock , DatetimeBlock ):
2248
2268
""" implement a datetime64 block with a tz attribute """
@@ -2500,6 +2520,9 @@ def to_native_types(self, slicer=None, na_rep=None, quoting=None, **kwargs):
2500
2520
def external_values (self ):
2501
2521
return np .asarray (self .values .astype ("timedelta64[ns]" , copy = False ))
2502
2522
2523
+ def array_values (self ) -> ExtensionArray :
2524
+ return TimedeltaArray ._simple_new (self .values )
2525
+
2503
2526
2504
2527
class BoolBlock (NumericBlock ):
2505
2528
__slots__ = ()
0 commit comments