-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Functions that rely on hash tables are incorrect for complex numbers #17927
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
Comments
yep, complex doesn't have much testing, nor likely is fully supported. nice first test. |
pandas/pandas/core/algorithms.py Line 80 in f5cc078
@jreback |
@heckeop sure |
After a bit of digging, it seems that the issue, at least for
We should then be able to add the complex type to pandas/pandas/_libs/hashtable_func_helper.pxi.in Lines 14 to 19 in f8ace5f
|
As a quick fix, could we treat complex numbers as objects and use the generic hasher? |
This is a dev branch to get feedback on some ideas. The generic hasher seems to work, but here are a few observations
Still need to test |
It looks like this is also affecting categorical dtypes, i.e. pd.Series([complex(6, 0), complex(1, 2), complex(3, -1)], dtype="category")
->
0 6.0
1 1.0
2 3.0
dtype: category
Categories (3, float64): [1.0, 3.0, 6.0] Might be another useful test case for @alimcmaster1 (which, thank you for taking this up). |
It looks like various functions that rely on hash tables fail when complex numbers are present, as it appears they only use the real component.
Consider the following list of values:
Using
value_counts
:Using
unique
:Using
duplicated
:Using
isin
:Using
factorize
fails as described in #16399, and multiple other functions fail in similar ways (rank
,nunique
,mode
, etc.).Note that these appear to work if the
dtype
is explicitly set toobject
instead ofcomplex64
:Output of
pd.show_versions()
INSTALLED VERSIONS
commit: 51c5f4d
python: 3.6.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 78 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.21.0rc1+26.g51c5f4d
pytest: 3.1.2
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
pyarrow: 0.6.0
xarray: 0.9.6
IPython: 6.1.0
sphinx: 1.5.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.4.2
numexpr: 2.6.2
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: None
html5lib: 0.999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: 0.1.0
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: