-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DEPR: remove FrozenNDarray #29840
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
DEPR: remove FrozenNDarray #29840
Changes from 2 commits
7d8dce2
99191ce
c6ebba5
8d5d82b
7bfa03a
4e288b4
de526b7
98c508d
e5d019a
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from pandas.errors import PerformanceWarning, UnsortedIndexError | ||
from pandas.util._decorators import Appender, cache_readonly | ||
|
||
from pandas.core.dtypes.cast import coerce_indexer_dtype | ||
from pandas.core.dtypes.common import ( | ||
ensure_int64, | ||
ensure_platform_int, | ||
|
@@ -40,7 +41,7 @@ | |
_index_shared_docs, | ||
ensure_index, | ||
) | ||
from pandas.core.indexes.frozen import FrozenList, _ensure_frozen | ||
from pandas.core.indexes.frozen import FrozenList | ||
import pandas.core.missing as missing | ||
from pandas.core.sorting import ( | ||
get_group_index, | ||
|
@@ -810,6 +811,13 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True): | |
def codes(self): | ||
return self._codes | ||
|
||
def _coerce(self, array_like, categories, copy=False): | ||
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. can you make this a free function, add types & a doc-string |
||
array_like = coerce_indexer_dtype(array_like, categories) | ||
if copy: | ||
array_like = array_like.copy() | ||
array_like.flags.writeable = False | ||
return array_like | ||
|
||
def _set_codes( | ||
self, codes, level=None, copy=False, validate=True, verify_integrity=False | ||
): | ||
|
@@ -821,17 +829,15 @@ def _set_codes( | |
|
||
if level is None: | ||
new_codes = FrozenList( | ||
_ensure_frozen(level_codes, lev, copy=copy)._shallow_copy() | ||
self._coerce(level_codes, lev, copy=copy).view() | ||
for lev, level_codes in zip(self._levels, codes) | ||
) | ||
else: | ||
level_numbers = [self._get_level_number(lev) for lev in level] | ||
new_codes = list(self._codes) | ||
for lev_num, level_codes in zip(level_numbers, codes): | ||
lev = self.levels[lev_num] | ||
new_codes[lev_num] = _ensure_frozen( | ||
level_codes, lev, copy=copy | ||
)._shallow_copy() | ||
new_codes[lev_num] = self._coerce(level_codes, lev, copy=copy) | ||
new_codes = FrozenList(new_codes) | ||
|
||
if verify_integrity: | ||
|
@@ -1095,7 +1101,8 @@ def _format_native_types(self, na_rep="nan", **kwargs): | |
if mask.any(): | ||
nan_index = len(level) | ||
level = np.append(level, na_rep) | ||
level_codes = level_codes.values() | ||
assert not level_codes.flags.writeable # i.e. copy is needed | ||
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. shoulnt' you be calling _coerce_indexer_frozen here (with copy=True)? 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. no, _coerce_indexer_frozen returns an ndarrary that is not writeable, whereas here we have a non-writeable ndarray and need to get a writeable copy |
||
level_codes = level_codes.copy() # make writeable | ||
level_codes[mask] = nan_index | ||
new_levels.append(level) | ||
new_codes.append(level_codes) | ||
|
@@ -2000,7 +2007,7 @@ def _assert_take_fillable( | |
if mask.any(): | ||
masked = [] | ||
for new_label in taken: | ||
label_values = new_label.values() | ||
label_values = new_label | ||
label_values[mask] = na_value | ||
masked.append(np.asarray(label_values)) | ||
taken = masked | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space