|
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
|
|
125 | 125 | transform,
|
126 | 126 | )
|
127 | 127 | from pandas.core.arrays import Categorical, ExtensionArray
|
128 |
| -from pandas.core.arrays.datetimelike import DatetimeLikeArrayMixin as DatetimeLikeArray |
129 | 128 | from pandas.core.arrays.sparse import SparseFrameAccessor
|
130 | 129 | from pandas.core.construction import extract_array
|
131 | 130 | from pandas.core.generic import NDFrame, _shared_docs
|
132 | 131 | from pandas.core.indexes import base as ibase
|
133 | 132 | from pandas.core.indexes.api import Index, ensure_index, ensure_index_from_sequences
|
134 |
| -from pandas.core.indexes.datetimes import DatetimeIndex |
135 | 133 | from pandas.core.indexes.multi import MultiIndex, maybe_droplevels
|
136 |
| -from pandas.core.indexes.period import PeriodIndex |
137 | 134 | from pandas.core.indexing import check_bool_indexer, convert_to_index_sliceable
|
138 | 135 | from pandas.core.internals import BlockManager
|
139 | 136 | from pandas.core.internals.construction import (
|
@@ -4849,46 +4846,6 @@ class max type
|
4849 | 4846 | else:
|
4850 | 4847 | new_obj = self.copy()
|
4851 | 4848 |
|
4852 |
| - def _maybe_casted_values(index, labels=None): |
4853 |
| - values = index._values |
4854 |
| - if not isinstance(index, (PeriodIndex, DatetimeIndex)): |
4855 |
| - if values.dtype == np.object_: |
4856 |
| - values = lib.maybe_convert_objects(values) |
4857 |
| - |
4858 |
| - # if we have the labels, extract the values with a mask |
4859 |
| - if labels is not None: |
4860 |
| - mask = labels == -1 |
4861 |
| - |
4862 |
| - # we can have situations where the whole mask is -1, |
4863 |
| - # meaning there is nothing found in labels, so make all nan's |
4864 |
| - if mask.size > 0 and mask.all(): |
4865 |
| - dtype = index.dtype |
4866 |
| - fill_value = na_value_for_dtype(dtype) |
4867 |
| - values = construct_1d_arraylike_from_scalar( |
4868 |
| - fill_value, len(mask), dtype |
4869 |
| - ) |
4870 |
| - else: |
4871 |
| - values = values.take(labels) |
4872 |
| - |
4873 |
| - # TODO(https://github.com/pandas-dev/pandas/issues/24206) |
4874 |
| - # Push this into maybe_upcast_putmask? |
4875 |
| - # We can't pass EAs there right now. Looks a bit |
4876 |
| - # complicated. |
4877 |
| - # So we unbox the ndarray_values, op, re-box. |
4878 |
| - values_type = type(values) |
4879 |
| - values_dtype = values.dtype |
4880 |
| - |
4881 |
| - if issubclass(values_type, DatetimeLikeArray): |
4882 |
| - values = values._data # TODO: can we de-kludge yet? |
4883 |
| - |
4884 |
| - if mask.any(): |
4885 |
| - values, _ = maybe_upcast_putmask(values, mask, np.nan) |
4886 |
| - |
4887 |
| - if issubclass(values_type, DatetimeLikeArray): |
4888 |
| - values = values_type(values, dtype=values_dtype) |
4889 |
| - |
4890 |
| - return values |
4891 |
| - |
4892 | 4849 | new_index = ibase.default_index(len(new_obj))
|
4893 | 4850 | if level is not None:
|
4894 | 4851 | if not isinstance(level, (tuple, list)):
|
@@ -4931,7 +4888,7 @@ def _maybe_casted_values(index, labels=None):
|
4931 | 4888 | name_lst += [col_fill] * missing
|
4932 | 4889 | name = tuple(name_lst)
|
4933 | 4890 | # to ndarray and maybe infer different dtype
|
4934 |
| - level_values = _maybe_casted_values(lev, lab) |
| 4891 | + level_values = maybe_casted_values(lev, lab) |
4935 | 4892 | new_obj.insert(0, name, level_values)
|
4936 | 4893 |
|
4937 | 4894 | new_obj.index = new_index
|
|
0 commit comments