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
@@ -195,6 +202,7 @@ def is_categorical_astype(self, dtype):
195202 def external_values (self ):
196203 """
197204 The array that Series.values returns (public attribute).
205+
198206 This has some historical constraints, and is overridden in block
199207 subclasses to return the correct array (e.g. period returns
200208 object ndarray and datetimetz a datetime64[ns] ndarray instead of
@@ -208,6 +216,12 @@ def internal_values(self):
208216 """
209217 return self .values
210218
219+ def array_values (self ) -> ExtensionArray :
220+ """
221+ The array that Series.array returns. Always an ExtensionArray.
222+ """
223+ return PandasArray (self .values )
224+
211225 def get_values (self , dtype = None ):
212226 """
213227 return an internal format, currently just the ndarray
@@ -1780,6 +1794,9 @@ def get_values(self, dtype=None):
17801794 values = values .reshape ((1 ,) + values .shape )
17811795 return values
17821796
1797+ def array_values (self ) -> ExtensionArray :
1798+ return self .values
1799+
17831800 def to_dense (self ):
17841801 return np .asarray (self .values )
17851802
@@ -2243,6 +2260,9 @@ def set(self, locs, values):
22432260 def external_values (self ):
22442261 return np .asarray (self .values .astype ("datetime64[ns]" , copy = False ))
22452262
2263+ def array_values (self ) -> ExtensionArray :
2264+ return DatetimeArray ._simple_new (self .values )
2265+
22462266
22472267class DatetimeTZBlock (ExtensionBlock , DatetimeBlock ):
22482268 """ 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):
25002520 def external_values (self ):
25012521 return np .asarray (self .values .astype ("timedelta64[ns]" , copy = False ))
25022522
2523+ def array_values (self ) -> ExtensionArray :
2524+ return TimedeltaArray ._simple_new (self .values )
2525+
25032526
25042527class BoolBlock (NumericBlock ):
25052528 __slots__ = ()
0 commit comments