-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Removed levels attribute from Categorical #13612
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 all 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 |
---|---|---|
|
@@ -1559,18 +1559,6 @@ def test_deprecated_labels(self): | |
res = cat.labels | ||
self.assert_numpy_array_equal(res, exp) | ||
|
||
def test_deprecated_levels(self): | ||
# TODO: levels is deprecated and should be removed in 0.18 or 2017, | ||
# whatever is earlier | ||
cat = pd.Categorical([1, 2, 3, np.nan], categories=[1, 2, 3]) | ||
exp = cat.categories | ||
with tm.assert_produces_warning(FutureWarning): | ||
res = cat.levels | ||
self.assert_index_equal(res, exp) | ||
with tm.assert_produces_warning(FutureWarning): | ||
res = pd.Categorical([1, 2, 3, np.nan], levels=[1, 2, 3]) | ||
self.assert_index_equal(res.categories, exp) | ||
|
||
def test_removed_names_produces_warning(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. no, all of the legacy pickles need to be an EARLIER version of pandas that HAS the .levels in the categorical. This is not testing anything. 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. in this case create, let's do a different way. create a pickle in 0.18.1 with the levels. save and create create a specific test to read back and validate. 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.
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. yes that IS what 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 you look at the comments 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. @JanSchulz : I agree. @jreback , there is no need to generate pickles with the 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. @gfyoung your comments indicate you don't understand my point. We don't have tests that have a 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 think we do: https://github.com/pydata/pandas/blob/master/pandas/tests/data/categorical_0_14_1.pickle contains a 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. ahh @JanSchulz yes I remember now. The issue is that we don't do this with anything else, and therefore they are in the wrong place (they really should have been in the generate_data scripts). ok @gfyoung can you move those 2 test to pandas/io/read_pickle (and the associated data files). Then they will be in the correct place. We do all pickle testing in a centralized place (except for round-tripping, which doesn't require data files). 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. Done. |
||
|
||
# 10482 | ||
|
@@ -4431,44 +4419,6 @@ def test_dt_accessor_api_for_categorical(self): | |
invalid.dt | ||
self.assertFalse(hasattr(invalid, 'str')) | ||
|
||
def test_pickle_v0_14_1(self): | ||
|
||
# we have the name warning | ||
# 10482 | ||
with tm.assert_produces_warning(UserWarning): | ||
cat = pd.Categorical(values=['a', 'b', 'c'], | ||
categories=['a', 'b', 'c', 'd'], | ||
name='foobar', ordered=False) | ||
pickle_path = os.path.join(tm.get_data_path(), | ||
'categorical_0_14_1.pickle') | ||
# This code was executed once on v0.14.1 to generate the pickle: | ||
# | ||
# cat = Categorical(labels=np.arange(3), levels=['a', 'b', 'c', 'd'], | ||
# name='foobar') | ||
# with open(pickle_path, 'wb') as f: pickle.dump(cat, f) | ||
# | ||
self.assert_categorical_equal(cat, pd.read_pickle(pickle_path)) | ||
|
||
def test_pickle_v0_15_2(self): | ||
# ordered -> _ordered | ||
# GH 9347 | ||
|
||
# we have the name warning | ||
# 10482 | ||
with tm.assert_produces_warning(UserWarning): | ||
cat = pd.Categorical(values=['a', 'b', 'c'], | ||
categories=['a', 'b', 'c', 'd'], | ||
name='foobar', ordered=False) | ||
pickle_path = os.path.join(tm.get_data_path(), | ||
'categorical_0_15_2.pickle') | ||
# This code was executed once on v0.15.2 to generate the pickle: | ||
# | ||
# cat = Categorical(labels=np.arange(3), levels=['a', 'b', 'c', 'd'], | ||
# name='foobar') | ||
# with open(pickle_path, 'wb') as f: pickle.dump(cat, f) | ||
# | ||
self.assert_categorical_equal(cat, pd.read_pickle(pickle_path)) | ||
|
||
def test_concat_categorical(self): | ||
# See GH 10177 | ||
df1 = pd.DataFrame( | ||
|
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.
iirc there is some unpick code that we should think about
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.
https://github.com/gfyoung/pandas/blob/4f88df4b85682fd003a5d730013b87ebec5ca8ea/pandas/core/categorical.py#L975
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.
IMO it would be ok to keep the old compat code in the pickle codepaths...
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.
Agree with @JanSchulz : I don't think we should remove that code-path right away.