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
@@ -193,7 +200,14 @@ def is_categorical_astype(self, dtype):
193
200
return False
194
201
195
202
def external_values (self , dtype = None ):
196
- """ return an outside world format, currently just the ndarray """
203
+ """
204
+ The array that Series.values returns (public attribute).
205
+
206
+ This has some historical constraints, and is overridden in block
207
+ subclasses to return the correct array (e.g. period returns
208
+ object ndarray and datetimetz a datetime64[ns] ndarray instead of
209
+ proper extension array).
210
+ """
197
211
return self .values
198
212
199
213
def internal_values (self , dtype = None ):
@@ -202,6 +216,12 @@ def internal_values(self, dtype=None):
202
216
"""
203
217
return self .values
204
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
+
205
225
def get_values (self , dtype = None ):
206
226
"""
207
227
return an internal format, currently just the ndarray
@@ -1770,6 +1790,9 @@ def get_values(self, dtype=None):
1770
1790
values = values .reshape ((1 ,) + values .shape )
1771
1791
return values
1772
1792
1793
+ def array_values (self ) -> ExtensionArray :
1794
+ return self .values
1795
+
1773
1796
def to_dense (self ):
1774
1797
return np .asarray (self .values )
1775
1798
@@ -2233,6 +2256,9 @@ def set(self, locs, values):
2233
2256
def external_values (self ):
2234
2257
return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
2235
2258
2259
+ def array_values (self ) -> ExtensionArray :
2260
+ return DatetimeArray ._simple_new (self .values )
2261
+
2236
2262
2237
2263
class DatetimeTZBlock (ExtensionBlock , DatetimeBlock ):
2238
2264
""" implement a datetime64 block with a tz attribute """
@@ -2490,6 +2516,9 @@ def to_native_types(self, slicer=None, na_rep=None, quoting=None, **kwargs):
2490
2516
def external_values (self , dtype = None ):
2491
2517
return np .asarray (self .values .astype ("timedelta64[ns]" , copy = False ))
2492
2518
2519
+ def array_values (self ) -> ExtensionArray :
2520
+ return TimedeltaArray ._simple_new (self .values )
2521
+
2493
2522
2494
2523
class BoolBlock (NumericBlock ):
2495
2524
__slots__ = ()
0 commit comments