You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several ways to trigger the bug, either of them resulting in isin returning all False whereas some indexes should be True.
Take the example above, we have the tuple (-1,-2,-3) repeated twice, and it can be checked that both counts and counts_idxs are 2 and (-1,-2,-3), respectively. Then, independently from the rest of the products, the resulting dataset from taking the idxs from isin should have, at least, 2 items. Calling the function as is, does not. Explanation, causes and possible solutions below:
Manually importing from pandas.core.algorithms import isin and settings idxs = isin(df['products'], counts[counts >= 2].index) results in the exact same behaviour.
I've tried to reproduce this same behaviour when not using tuples at all and I can't seem to succeed.
This results in 0.20.x relying in numpy.in1d whereas 0.19.x used lib.ismember, which is equivalent to htable.ismember_object in 0.20.x. One can confirm this becase:
Now, either this is temporally fixed in pandas by not relying in in1d or an issue is submitted to numpy (which I will do once I can take a look at in1d and see what's happening). Also, one can solve it by not using tuples at all, and applying hash beforehand, for example.
I've narrowed a bit more the problem and it is not only related to n but also prodmax:
Any combination with n > 1000001 && prodmax > 1986 produces and empty dataframe:
Code Sample
Problem description
There are several ways to trigger the bug, either of them resulting in
isin
returning allFalse
whereas some indexes should beTrue
.Take the example above, we have the tuple
(-1,-2,-3)
repeated twice, and it can be checked that bothcounts
andcounts_idxs
are2
and(-1,-2,-3)
, respectively. Then, independently from the rest of theproducts
, the resulting dataset from taking theidxs
fromisin
should have, at least, 2 items. Calling the function as is, does not. Explanation, causes and possible solutions below:Manually importing
from pandas.core.algorithms import isin
and settingsidxs = isin(df['products'], counts[counts >= 2].index)
results in the exact same behaviour.I've tried to reproduce this same behaviour when not using tuples at all and I can't seem to succeed.
Proposed solution
This seems to be a regression in
0.20.x
as using latest0.19.x
(0.19.2) works perfectly fine. Indeed, manually copyingisin
from0.19.x
and using it instead of0.20.x
works. One can see that a particular if was reversed/erased inhttps://github.com/pandas-dev/pandas/blob/master/pandas/core/algorithms.py#L414
and
https://github.com/pandas-dev/pandas/blob/v0.19.2/pandas/core/algorithms.py#L144
https://github.com/pandas-dev/pandas/blob/v0.19.2/pandas/core/algorithms.py#L161
This results in
0.20.x
relying innumpy.in1d
whereas0.19.x
usedlib.ismember
, which is equivalent tohtable.ismember_object
in0.20.x
. One can confirm this becase:works fine, whereas
silently fails.
Now, either this is temporally fixed in pandas by not relying in
in1d
or an issue is submitted to numpy (which I will do once I can take a look atin1d
and see what's happening). Also, one can solve it by not using tuples at all, and applyinghash
beforehand, for example.I've narrowed a bit more the problem and it is not only related to
n
but alsoprodmax
:Any combination with
n > 1000001 && prodmax > 1986
produces and empty dataframe:Whereas having
n <= 1000000
orprodmax <= 1986
works just fine. Parameter values have been deduced from:n
from https://github.com/pandas-dev/pandas/blob/master/pandas/core/algorithms.py#L414prodmax
by binary search:Output of
pd.show_versions()
pandas: 0.20.3
pytest: 3.0.5
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.25.2
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 5.1.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 3.7.2
bs4: 4.5.3
html5lib: None
sqlalchemy: 1.1.5
pymysql: None
psycopg2: None
jinja2: 2.9.4
s3fs: None
pandas_gbq: None
pandas_datareader: None
This has been confirmed and tested in multiple pcs and environments, always Python 3.x
The text was updated successfully, but these errors were encountered: