Skip to content

BUG: value_counts() is non-reproducible from one run to another #35862

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
1 task
BaruchYoussin opened this issue Aug 23, 2020 · 1 comment
Closed
1 task

BUG: value_counts() is non-reproducible from one run to another #35862

BaruchYoussin opened this issue Aug 23, 2020 · 1 comment

Comments

@BaruchYoussin
Copy link

  • [X ] I have checked that this issue has not already been reported.

  • [X ] I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import numpy as np
import pandas as pd

ser = pd.Series(data=['n1', 'n2', 'n0', 'n4', 'n2', 'n1', 'n0', 'n3'], name='ser')

for _ in range(3):
    np.random.seed(42)
    print(ser.value_counts())
    print(ser.value_counts(sort=False))

Problem description

The output of this file changes from one run to another. This creates a randomality which cannot be reproduced by np.random.seed(..).

Due to this randomality, the code cannot be made reproducible.

This non-reproducibility happens only from one run to the other; the loop in the code shows that the output is repeated exactly within the same run.

The code shows that the non-reproducibility happens both with value_counts(sort=True) (default value) and value_counts(sort=False).

Expected Output

Should be the same from one run to another.

Note

This could be related to #32514 or #32449 but I do not quite understand this.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2ca0a2
python : 3.6.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-112-generic
Version : #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 49.6.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@BaruchYoussin BaruchYoussin added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 23, 2020
@jreback
Copy link
Contributor

jreback commented Aug 23, 2020

np.random.seed is not used for hashing at all

you can set PYTHONHASHSEED for deterministic hashing between runs of the interpreter: https://stackoverflow.com/questions/30585108/disable-hash-randomization-from-within-python-program

@jreback jreback added Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 23, 2020
@jreback jreback added this to the No action milestone Aug 23, 2020
@jreback jreback closed this as completed Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants