-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DEPR: deprecate .asobject property #18572
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 2 commits
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 |
---|---|---|
|
@@ -242,6 +242,13 @@ def _box_values(self, values): | |
""" | ||
return lib.map_infer(values, self._box_func) | ||
|
||
def _box_values_as_index(self): | ||
""" | ||
return object Index which contains boxed values | ||
""" | ||
from pandas.core.index import Index | ||
return Index(self._box_values(self.asi8), name=self.name, dtype=object) | ||
|
||
def _format_with_header(self, header, **kwargs): | ||
return header + list(self._format_native_types(**kwargs)) | ||
|
||
|
@@ -360,7 +367,7 @@ def map(self, f): | |
raise TypeError('The map function must return an Index object') | ||
return result | ||
except Exception: | ||
return self.asobject.map(f) | ||
return self.astype(object).map(f) | ||
|
||
def sort_values(self, return_indexer=False, ascending=True): | ||
""" | ||
|
@@ -424,13 +431,15 @@ def _isnan(self): | |
|
||
@property | ||
def asobject(self): | ||
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 actually want to completely remove 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. Jeff, is it used in 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.
and that should be addressed as well. no its not. much better to fix this. otherwise this is just kicking the can. 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. If this method is only used there, what is the problem? Then it is a perfect example of a common private helper method that our classes are full of.
Then please indicate what you mean with "fix" |
||
""" | ||
"""DEPRECATED: Use ``astype(object)`` instead. | ||
|
||
return object Index which contains boxed values | ||
|
||
*this is an internal non-public method* | ||
""" | ||
from pandas.core.index import Index | ||
return Index(self._box_values(self.asi8), name=self.name, dtype=object) | ||
warnings.warn("'asobject' is deprecated. Use 'astype(object)'" | ||
" instead", FutureWarning, stacklevel=2) | ||
return self.astype(object) | ||
|
||
def _convert_tolerance(self, tolerance, target): | ||
tolerance = np.asarray(to_timedelta(tolerance, box=False)) | ||
|
@@ -468,7 +477,7 @@ def tolist(self): | |
""" | ||
return a list of the underlying data | ||
""" | ||
return list(self.asobject) | ||
return list(self.astype(object)) | ||
|
||
def min(self, axis=None, *args, **kwargs): | ||
""" | ||
|
@@ -746,7 +755,7 @@ def isin(self, values): | |
try: | ||
values = type(self)(values) | ||
except ValueError: | ||
return self.asobject.isin(values) | ||
return self.astype(object).isin(values) | ||
|
||
return algorithms.isin(self.asi8, values.asi8) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,10 @@ def test_map_dictlike(self, mapper): | |
expected = pd.Index([np.nan] * len(self.index)) | ||
result = self.index.map(mapper([], [])) | ||
tm.assert_index_equal(result, expected) | ||
|
||
def test_asobject_deprecated(self): | ||
# GH18572 | ||
d = self.create_index() | ||
with tm.assert_produces_warning(FutureWarning): | ||
i = d.asobject | ||
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. you can do the assert inside the with 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. print here as well |
||
assert isinstance(i, pd.Index) |
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.
see what effect of removing this does
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.
Two tests fail, both at
pandas\tests\test_categorical.py:811
(parameterized tests, of categorical of dtype='timedelta64[h]' and is_ordered=True).