|
83 | 83 | infer_dtype_from_scalar,
|
84 | 84 | invalidate_string_dtypes,
|
85 | 85 | maybe_cast_to_datetime,
|
| 86 | + maybe_casted_values, |
86 | 87 | maybe_convert_platform,
|
87 | 88 | maybe_downcast_to_dtype,
|
88 | 89 | maybe_infer_to_datetimelike,
|
89 | 90 | maybe_upcast,
|
90 |
| - maybe_upcast_putmask, |
91 | 91 | validate_numeric_casting,
|
92 | 92 | )
|
93 | 93 | from pandas.core.dtypes.common import (
|
|
114 | 114 | needs_i8_conversion,
|
115 | 115 | pandas_dtype,
|
116 | 116 | )
|
117 |
| -from pandas.core.dtypes.missing import isna, na_value_for_dtype, notna |
| 117 | +from pandas.core.dtypes.missing import isna, notna |
118 | 118 |
|
119 | 119 | from pandas.core import algorithms, common as com, nanops, ops
|
120 | 120 | from pandas.core.accessor import CachedAccessor
|
121 | 121 | from pandas.core.aggregation import reconstruct_func, relabel_result, transform
|
122 | 122 | from pandas.core.arrays import Categorical, ExtensionArray
|
123 |
| -from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin as DatetimeLikeArray |
124 | 123 | from pandas.core.arrays.sparse import SparseFrameAccessor
|
125 | 124 | from pandas.core.construction import extract_array
|
126 | 125 | from pandas.core.generic import NDFrame, _shared_docs
|
127 | 126 | from pandas.core.indexes import base as ibase
|
128 | 127 | from pandas.core.indexes.api import Index, ensure_index, ensure_index_from_sequences
|
129 |
| -from pandas.core.indexes.datetimes import DatetimeIndex |
130 | 128 | from pandas.core.indexes.multi import MultiIndex, maybe_droplevels
|
131 |
| -from pandas.core.indexes.period import PeriodIndex |
132 | 129 | from pandas.core.indexing import check_bool_indexer, convert_to_index_sliceable
|
133 | 130 | from pandas.core.internals import BlockManager
|
134 | 131 | from pandas.core.internals.construction import (
|
@@ -4842,46 +4839,6 @@ class max type
|
4842 | 4839 | else:
|
4843 | 4840 | new_obj = self.copy()
|
4844 | 4841 |
|
4845 |
| - def _maybe_casted_values(index, labels=None): |
4846 |
| - values = index._values |
4847 |
| - if not isinstance(index, (PeriodIndex, DatetimeIndex)): |
4848 |
| - if values.dtype == np.object_: |
4849 |
| - values = lib.maybe_convert_objects(values) |
4850 |
| - |
4851 |
| - # if we have the labels, extract the values with a mask |
4852 |
| - if labels is not None: |
4853 |
| - mask = labels == -1 |
4854 |
| - |
4855 |
| - # we can have situations where the whole mask is -1, |
4856 |
| - # meaning there is nothing found in labels, so make all nan's |
4857 |
| - if mask.size > 0 and mask.all(): |
4858 |
| - dtype = index.dtype |
4859 |
| - fill_value = na_value_for_dtype(dtype) |
4860 |
| - values = construct_1d_arraylike_from_scalar( |
4861 |
| - fill_value, len(mask), dtype |
4862 |
| - ) |
4863 |
| - else: |
4864 |
| - values = values.take(labels) |
4865 |
| - |
4866 |
| - # TODO(https://github.com/pandas-dev/pandas/issues/24206) |
4867 |
| - # Push this into maybe_upcast_putmask? |
4868 |
| - # We can't pass EAs there right now. Looks a bit |
4869 |
| - # complicated. |
4870 |
| - # So we unbox the ndarray_values, op, re-box. |
4871 |
| - values_type = type(values) |
4872 |
| - values_dtype = values.dtype |
4873 |
| - |
4874 |
| - if issubclass(values_type, DatetimeLikeArray): |
4875 |
| - values = values._data # TODO: can we de-kludge yet? |
4876 |
| - |
4877 |
| - if mask.any(): |
4878 |
| - values, _ = maybe_upcast_putmask(values, mask, np.nan) |
4879 |
| - |
4880 |
| - if issubclass(values_type, DatetimeLikeArray): |
4881 |
| - values = values_type(values, dtype=values_dtype) |
4882 |
| - |
4883 |
| - return values |
4884 |
| - |
4885 | 4842 | new_index = ibase.default_index(len(new_obj))
|
4886 | 4843 | if level is not None:
|
4887 | 4844 | if not isinstance(level, (tuple, list)):
|
@@ -4924,7 +4881,7 @@ def _maybe_casted_values(index, labels=None):
|
4924 | 4881 | name_lst += [col_fill] * missing
|
4925 | 4882 | name = tuple(name_lst)
|
4926 | 4883 | # to ndarray and maybe infer different dtype
|
4927 |
| - level_values = _maybe_casted_values(lev, lab) |
| 4884 | + level_values = maybe_casted_values(lev, lab) |
4928 | 4885 | new_obj.insert(0, name, level_values)
|
4929 | 4886 |
|
4930 | 4887 | new_obj.index = new_index
|
|
0 commit comments