Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Use np.random's RandomState when seed is None #13161
Conversation
shoyer
and 1 other
commented on an outdated diff
May 12, 2016
| @@ -2072,7 +2072,7 @@ def _random_state(state=None): | ||
| elif isinstance(state, np.random.RandomState): | ||
| return state | ||
| elif state is None: | ||
| - return np.random.RandomState() | ||
| + return np.random.mtrand._rand |
shoyer
Member
|
shoyer
and 1 other
commented on an outdated diff
May 12, 2016
| @@ -415,6 +415,10 @@ def test_sample(self): | ||
| o.sample(frac=0.7, random_state=np.random.RandomState(test)), | ||
| o.sample(frac=0.7, random_state=np.random.RandomState(test))) | ||
| + np.random.seed(test) | ||
| + self._compare(o.sample(n=4), o.sample(n=4)) |
shoyer
Member
|
jreback
added Numeric Compat
labels
May 13, 2016
|
@ariddell pls also add a whatsnew entry. I would do it in API changes section. |
|
@jreback added. Thanks! |
|
@ariddell could you please fix the use of NumPy's private state as noted above? This is something simple that could avoid significant pain down the road. |
|
Fair enough. What should the seed be? Did you mean |
|
@ariddell Yes, I meant |
|
Using |
|
Let's just return |
|
@shoyer duck typing it is. |
shoyer
commented on the diff
May 17, 2016
| @@ -2072,7 +2072,7 @@ def _random_state(state=None): | ||
| elif isinstance(state, np.random.RandomState): | ||
| return state | ||
| elif state is None: | ||
| - return np.random.RandomState() | ||
| + return np.random |
ariddell
Contributor
|
jreback
added this to the
0.18.2
milestone
May 18, 2016
|
you have a failing test |
|
@ariddell can you rebase / update |
|
OK. I think I've got it. |
jreback
closed this
in 6f90340
May 21, 2016
|
thanks @ariddell |
nps
added a commit
to nps/pandas
that referenced
this pull request
May 30, 2016
|
|
+ nps |
72d6963
|
pydolan
commented
Feb 9, 2017
•
|
I'm not getting the behavior I'd expect from this fix in Pandas 0.19.2. Example:
Any thoughts on why |
|
@pydolan is there a missing |
pydolan
commented
Feb 9, 2017
|
@shoyer -- sorry about that; will update example with my actual code (i.e., with the one missing line) |
|
@pydolan It looks like you are calling |
pydolan
commented
Feb 9, 2017
|
If I move the
Note that this time, the first call to (Also note that I did verify that calling |
This is working as intended. Try just sampling random numbers from numpy -- it does the exact same thing. |
pydolan
commented
Feb 9, 2017
|
Good point; I completely spaced on the nature of random sampling. Sorry for the waste of time! |
ariddell commentedMay 12, 2016
•
edited
git diff upstream/master | flake8 --diffThe handle for numpy's current random state is
np.random.mtrand._rand.Compare https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/utils/validation.py#L573