|
14 | 14 | registry)
|
15 | 15 | from pandas.core.dtypes.generic import (
|
16 | 16 | ABCCategorical, ABCCategoricalIndex, ABCDateOffset, ABCDatetimeIndex,
|
17 |
| - ABCIndexClass, ABCPandasArray, ABCPeriodArray, ABCPeriodIndex, ABCSeries, |
18 |
| - ABCSparseArray, ABCSparseSeries) |
| 17 | + ABCIndexClass, ABCPeriodArray, ABCPeriodIndex, ABCSeries, ABCSparseArray, |
| 18 | + ABCSparseSeries) |
19 | 19 | from pandas.core.dtypes.inference import ( # noqa:F401
|
20 | 20 | is_array_like, is_bool, is_complex, is_decimal, is_dict_like, is_file_like,
|
21 | 21 | is_float, is_hashable, is_integer, is_interval, is_iterator, is_list_like,
|
@@ -2016,54 +2016,3 @@ def pandas_dtype(dtype):
|
2016 | 2016 | raise TypeError("dtype '{}' not understood".format(dtype))
|
2017 | 2017 |
|
2018 | 2018 | return npdtype
|
2019 |
| - |
2020 |
| - |
2021 |
| -def extract_array(obj, extract_numpy=False): |
2022 |
| - """ |
2023 |
| - Extract the ndarray or ExtensionArray from a Series or Index. |
2024 |
| -
|
2025 |
| - For all other types, `obj` is just returned as is. |
2026 |
| -
|
2027 |
| - Parameters |
2028 |
| - ---------- |
2029 |
| - obj : object |
2030 |
| - For Series / Index, the underlying ExtensionArray is unboxed. |
2031 |
| - For Numpy-backed ExtensionArrays, the ndarray is extracted. |
2032 |
| -
|
2033 |
| - extract_numpy : bool, default False |
2034 |
| - Whether to extract the ndarray from a PandasArray |
2035 |
| -
|
2036 |
| - Returns |
2037 |
| - ------- |
2038 |
| - arr : object |
2039 |
| -
|
2040 |
| - Examples |
2041 |
| - -------- |
2042 |
| - >>> extract_array(pd.Series(['a', 'b', 'c'], dtype='category')) |
2043 |
| - [a, b, c] |
2044 |
| - Categories (3, object): [a, b, c] |
2045 |
| -
|
2046 |
| - Other objects like lists, arrays, and DataFrames are just passed through. |
2047 |
| -
|
2048 |
| - >>> extract_array([1, 2, 3]) |
2049 |
| - [1, 2, 3] |
2050 |
| -
|
2051 |
| - For an ndarray-backed Series / Index a PandasArray is returned. |
2052 |
| -
|
2053 |
| - >>> extract_array(pd.Series([1, 2, 3])) |
2054 |
| - <PandasArray> |
2055 |
| - [1, 2, 3] |
2056 |
| - Length: 3, dtype: int64 |
2057 |
| -
|
2058 |
| - To extract all the way down to the ndarray, pass ``extract_numpy=True``. |
2059 |
| -
|
2060 |
| - >>> extract_array(pd.Series([1, 2, 3]), extract_numpy=True) |
2061 |
| - array([1, 2, 3]) |
2062 |
| - """ |
2063 |
| - if isinstance(obj, (ABCIndexClass, ABCSeries)): |
2064 |
| - obj = obj.array |
2065 |
| - |
2066 |
| - if extract_numpy and isinstance(obj, ABCPandasArray): |
2067 |
| - obj = obj._ndarray |
2068 |
| - |
2069 |
| - return obj |
0 commit comments