-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: conversion of Series to Categorical #16557
Conversation
@jreback this fixes the issue, could you review the PR and let me know if am doing it wrong. |
Codecov Report
@@ Coverage Diff @@
## master #16557 +/- ##
=======================================
Coverage 90.96% 90.96%
=======================================
Files 161 161
Lines 49263 49263
=======================================
Hits 44810 44810
Misses 4453 4453
Continue to review full report at Codecov.
|
pls add tests. in fact you want to write the tests first to make sure that they fail, then your fix makes it pass. also add a whatsnew entry (0.20.2) is fine. |
ca3404b
to
3e1d73f
Compare
pandas/tests/series/test_dtypes.py
Outdated
series = Series(['a', 'b', 'c']) | ||
|
||
categorical_series = Series(series, dtype='category') | ||
expected = Categorical(['a', 'b', 'c']) |
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.
I think you can mak this expected = Series(['a', 'b', 'c'], dtype='category')
and then you can use tm.assert_series_equal(categorical_series, expected)
.
27a955c
to
83dd40a
Compare
@TomAugspurger I have made the changes according to your comments, the build is failing for some reason, can you retrigger the travis build please? |
could you retrigger circleci build as well please. Thank you. |
@jreback @TomAugspurger Could you review the PR please, Thank you. |
doc/source/whatsnew/v0.20.2.txt
Outdated
@@ -59,6 +59,7 @@ Conversion | |||
|
|||
- Bug in :func:`to_numeric` in which empty data inputs were causing a segfault of the interpreter (:issue:`16302`) | |||
- Silence numpy warnings when broadcasting ``DataFrame`` to ``Series`` with comparison ops (:issue:`16378`, :issue:`16306`) | |||
- Bug in ``Series`` with dtype='category' (:issue:`16524`) |
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.
Bug in Series
construction with dtype='category'
pandas/tests/series/test_dtypes.py
Outdated
@@ -248,3 +248,11 @@ def test_intercept_astype_object(self): | |||
|
|||
result = df.values.squeeze() | |||
assert (result[:, 0] == expected.values).all() | |||
|
|||
def test_series_to_categorical(self): | |||
series = Series(['a', 'b', 'c']) |
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.
add comment for the issue number
pandas/tests/series/test_dtypes.py
Outdated
def test_series_to_categorical(self): | ||
series = Series(['a', 'b', 'c']) | ||
|
||
categorical_series = Series(series, dtype='category') |
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.
result =
pandas/tests/series/test_dtypes.py
Outdated
categorical_series = Series(series, dtype='category') | ||
expected = Series(['a', 'b', 'c'], dtype='category') | ||
|
||
tm.assert_series_equal(categorical_series, expected) |
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.
categorical_series -> result
pandas/core/categorical.py
Outdated
@@ -248,7 +248,8 @@ class Categorical(PandasObject): | |||
__array_priority__ = 1000 | |||
_typ = 'categorical' | |||
|
|||
def __init__(self, values, categories=None, ordered=False, fastpath=False): | |||
def __init__(self, values, categories=None, ordered=False, fastpath=False, |
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.
this fix should not be here.
instead in core/internals.py/Block/_astype.py
raise_one_error
can be a named argument in the signature and not passed to the constructor
80ed6da
to
b37fba3
Compare
@TomAugspurger @jreback I have made the changes according to your comments. |
@jreback hey I have made changes according to your previous comments, could you review the changes once. Thank You. |
@preddy5 I rebased and moved the release note to 0.20.3 (releasing in a couple weeks). I'll let Jeff comment on the changes, but I think we're good. |
doc/source/whatsnew/v0.20.3.txt
Outdated
@@ -44,6 +44,7 @@ Conversion | |||
^^^^^^^^^^ | |||
|
|||
- Bug in pickle compat prior to the v0.20.x series, when ``UTC`` is a timezone in a Series/DataFrame/Index (:issue:`16608`) | |||
- Bug in ``Series`` with ``dtype='category'`` (:issue:`16524`) |
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.
be a bit more descriptive.
Bug in Series construction when passing type=category
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.
tiny change. ping on green.
@preddy5 Thanks! |
fix pandas-dev#16524 (cherry picked from commit 9fdea65)
Patch to bug fix #16524