6666)
6767
6868import 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+ )
7077from pandas .core .base import PandasObject
7178import pandas .core .common as com
7279from pandas .core .construction import extract_array
@@ -193,7 +200,14 @@ def is_categorical_astype(self, dtype):
193200 return False
194201
195202 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+ """
197211 return self .values
198212
199213 def internal_values (self , dtype = None ):
@@ -202,6 +216,12 @@ def internal_values(self, dtype=None):
202216 """
203217 return self .values
204218
219+ def array_values (self ) -> ExtensionArray :
220+ """
221+ The array that Series.array returns. Always an ExtensionArray.
222+ """
223+ return PandasArray (self .values )
224+
205225 def get_values (self , dtype = None ):
206226 """
207227 return an internal format, currently just the ndarray
@@ -1770,6 +1790,9 @@ def get_values(self, dtype=None):
17701790 values = values .reshape ((1 ,) + values .shape )
17711791 return values
17721792
1793+ def array_values (self ) -> ExtensionArray :
1794+ return self .values
1795+
17731796 def to_dense (self ):
17741797 return np .asarray (self .values )
17751798
@@ -2233,6 +2256,9 @@ def set(self, locs, values):
22332256 def external_values (self ):
22342257 return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
22352258
2259+ def array_values (self ) -> ExtensionArray :
2260+ return DatetimeArray ._simple_new (self .values )
2261+
22362262
22372263class DatetimeTZBlock (ExtensionBlock , DatetimeBlock ):
22382264 """ 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):
24902516 def external_values (self , dtype = None ):
24912517 return np .asarray (self .values .astype ("timedelta64[ns]" , copy = False ))
24922518
2519+ def array_values (self ) -> ExtensionArray :
2520+ return TimedeltaArray ._simple_new (self .values )
2521+
24932522
24942523class BoolBlock (NumericBlock ):
24952524 __slots__ = ()
0 commit comments