-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: improve output for testing.assert_*_equal with Categoricals #18069
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
ENH: improve output for testing.assert_*_equal with Categoricals #18069
Conversation
cfd531f to
90f2aa4
Compare
pandas/util/testing.py
Outdated
| def raise_assert_detail(obj, message, left, right, diff=None): | ||
| if isinstance(left, np.ndarray): | ||
| left = pprint_thing(left) | ||
| elif pd.api.types.is_categorical_dtype(left): |
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.
Looks like is_categorical_dtype is already being imported from pandas.core.dtypes.common at the top of the file, so you should be able to just use is_categorical_dtype(left) here.
pandas/util/testing.py
Outdated
| left = repr(left) | ||
| if isinstance(right, np.ndarray): | ||
| right = pprint_thing(right) | ||
| elif pd.api.types.is_categorical_dtype(right): |
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.
same
doc/source/whatsnew/v0.21.1.txt
Outdated
| - Bug in :meth:`DataFrame.astype` where casting to 'category' on an empty ``DataFrame`` causes a segmentation fault (:issue:`18004`) | ||
| - | ||
| - Error messages in the testing module have been improved when items have | ||
| different CategoricalDtype (:issue:`18069`) |
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.
Can you add backticks to ``CategoricalDtype``? Looks like that's what was typically done in the previous whatsnew.
90f2aa4 to
fde514e
Compare
Codecov Report
@@ Coverage Diff @@
## master #18069 +/- ##
==========================================
+ Coverage 91.25% 91.26% +<.01%
==========================================
Files 163 163
Lines 50120 50120
==========================================
+ Hits 45737 45740 +3
+ Misses 4383 4380 -3
Continue to review full report at Codecov.
|
|
Alright, I've adjusted according to comments from @jschendel. |
|
thanks @topper-123 |
(cherry picked from commit bb4fa65)
(cherry picked from commit bb4fa65)
git diff upstream/master -u -- "*.py" | flake8 --diffThe new CategoricalDtype made the output from failing tests uninformative, see #18056.
The error message is now:
Which is much better.