-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
PERF: improve access of .array #31037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3ea30d0
8f5d886
d67dab8
b0afa10
4706b83
3ef079d
1185d44
f9f8631
53fd7e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,14 @@ | |
) | ||
|
||
import pandas.core.algorithms as algos | ||
from pandas.core.arrays import Categorical, DatetimeArray, PandasDtype, TimedeltaArray | ||
from pandas.core.arrays import ( | ||
Categorical, | ||
DatetimeArray, | ||
ExtensionArray, | ||
PandasArray, | ||
PandasDtype, | ||
TimedeltaArray, | ||
) | ||
from pandas.core.base import PandasObject | ||
import pandas.core.common as com | ||
from pandas.core.construction import extract_array | ||
|
@@ -195,6 +202,7 @@ def is_categorical_astype(self, dtype): | |
def external_values(self): | ||
""" | ||
The array that Series.values returns (public attribute). | ||
|
||
This has some historical constraints, and is overridden in block | ||
subclasses to return the correct array (e.g. period returns | ||
object ndarray and datetimetz a datetime64[ns] ndarray instead of | ||
|
@@ -208,6 +216,12 @@ def internal_values(self): | |
""" | ||
return self.values | ||
|
||
def array_values(self) -> ExtensionArray: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need external_values at all? this is getting very confusing with all of the values There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I clarified the docstrings (in this PR, but split off and already merged in #31103) to make it clear what |
||
""" | ||
The array that Series.array returns. Always an ExtensionArray. | ||
""" | ||
return PandasArray(self.values) | ||
|
||
def get_values(self, dtype=None): | ||
""" | ||
return an internal format, currently just the ndarray | ||
|
@@ -1777,6 +1791,9 @@ def get_values(self, dtype=None): | |
values = values.reshape((1,) + values.shape) | ||
return values | ||
|
||
def array_values(self) -> ExtensionArray: | ||
return self.values | ||
|
||
def to_dense(self): | ||
return np.asarray(self.values) | ||
|
||
|
@@ -2234,6 +2251,9 @@ def set(self, locs, values): | |
def external_values(self): | ||
return np.asarray(self.values.astype("datetime64[ns]", copy=False)) | ||
|
||
def array_values(self) -> ExtensionArray: | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return DatetimeArray._simple_new(self.values) | ||
|
||
|
||
class DatetimeTZBlock(ExtensionBlock, DatetimeBlock): | ||
""" implement a datetime64 block with a tz attribute """ | ||
|
@@ -2491,6 +2511,9 @@ def to_native_types(self, slicer=None, na_rep=None, quoting=None, **kwargs): | |
def external_values(self): | ||
return np.asarray(self.values.astype("timedelta64[ns]", copy=False)) | ||
|
||
def array_values(self) -> ExtensionArray: | ||
return TimedeltaArray._simple_new(self.values) | ||
|
||
|
||
class BoolBlock(NumericBlock): | ||
__slots__ = () | ||
|
Uh oh!
There was an error while loading. Please reload this page.