Skip to content

Categorical handles imaginary values incorrectly #16399

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

Closed
TomAugspurger opened this issue May 20, 2017 · 3 comments · Fixed by #53551
Closed

Categorical handles imaginary values incorrectly #16399

TomAugspurger opened this issue May 20, 2017 · 3 comments · Fixed by #53551
Assignees
Labels
Categorical Categorical Data Type Complex Complex Numbers Needs Tests Unit test(s) needed to prevent regressions

Comments

@TomAugspurger
Copy link
Contributor

TomAugspurger commented May 20, 2017

In [3]: import pandas as pd

In [4]: pd.Categorical([1, 2 + 2j])
Out[4]:
[1.0, 2.0]
Categories (2, float64): [1.0, 2.0]

In [6]: pd.Categorical([1, 2, 2 + 2j])
Out[6]:
[1.0, 2.0, 2.0]
Categories (2, float64): [1.0, 2.0]  # Missing a `2 + 2j` category

I think it comes down to factorize

In [9]: pd.factorize([1, 2, 2 + 1j])
Out[9]: (array([0, 1, 1]), array([ 1.,  2.]))

Clearly not much demand for this, but figured I'd park an issue anyway. Discovered this in #16015, which will not be fixing it.

@TomAugspurger TomAugspurger added Categorical Categorical Data Type Difficulty Intermediate Numeric Operations Arithmetic, Comparison, and Logical operations labels May 20, 2017
@TomAugspurger TomAugspurger added this to the Next Major Release milestone May 20, 2017
@jreback
Copy link
Contributor

jreback commented May 20, 2017

we convert complex to float (always have)

@jreback jreback added the Complex Complex Numbers label May 20, 2017
@TomAugspurger
Copy link
Contributor Author

we convert complex to float (always have)

Yeah, the float part is fine, it's the dropping the imaginary part (Out[6] should have three categories)

@jbrockmendel
Copy link
Member

I think this now works since we support Index[complex]. Could use test(s).

@jbrockmendel jbrockmendel added Needs Tests Unit test(s) needed to prevent regressions and removed Bug labels Feb 16, 2022
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Complex Complex Numbers Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants