Repository: modin-project/modin

Issue:
AttributeError: module 'numpy.random' has no attribute 'randomState'
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Ubuntu 18.04
- **Modin version** (`modin.__version__`):  0.7.4
- **Python version**: 3.7.6
- **Code we can use to reproduce**: 
```python
import modin.pandas as mpd
import numpy as np

rng = np.random.RandomState(42)
df = mpd.DataFrame(np.random.rand(100, 3))
df = df.sample(n=50, random_state=rng)
```
<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->
The `DataFrame.sample()` function, when passed the `random_state` argument, raised an AttributeError when calling Numpy (I'm using Numpy 1.18.5). See tracebacks below. 

### Source code / logs
<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->
It looks like in `base.py` Line 2483, `np.random.randomState` should be `np.random.RandomState`.
```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-667e79aa734e> in <module>
      1 rng = np.random.RandomState(42)
      2 df = mpd.DataFrame(np.random.rand(100, 3))
----> 3 df = df.sample(n=50, random_state=rng)

/export/home/software/anaconda3/lib/python3.7/site-packages/modin/pandas/base.py in sample(self, n, frac, replace, weights, random_state, axis)
   2481             if isinstance(random_state, int):
   2482                 random_num_gen = np.random.RandomState(random_state)
-> 2483             elif isinstance(random_state, np.random.randomState):
   2484                 random_num_gen = random_state
   2485             else:

AttributeError: module 'numpy.random' has no attribute 'randomState'
```

AttributeError: module 'numpy.random' has no attribute 'randomState'
### System information
- **OS Platform and Distribution (e.g., Linux Ubuntu 16.04)**: Ubuntu 18.04
- **Modin version** (`modin.__version__`):  0.7.4
- **Python version**: 3.7.6
- **Code we can use to reproduce**: 
```python
import modin.pandas as mpd
import numpy as np

rng = np.random.RandomState(42)
df = mpd.DataFrame(np.random.rand(100, 3))
df = df.sample(n=50, random_state=rng)
```
<!--
You can obtain the Modin version with

python -c "import modin; print(modin.__version__)"
-->

### Describe the problem
<!-- Describe the problem clearly here. -->
The `DataFrame.sample()` function, when passed the `random_state` argument, raised an AttributeError when calling Numpy (I'm using Numpy 1.18.5). See tracebacks below. 

### Source code / logs
<!-- Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached. Try to provide a reproducible test case that is the bare minimum necessary to generate the problem. -->
It looks like in `base.py` Line 2483, `np.random.randomState` should be `np.random.RandomState`.
```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-667e79aa734e> in <module>
      1 rng = np.random.RandomState(42)
      2 df = mpd.DataFrame(np.random.rand(100, 3))
----> 3 df = df.sample(n=50, random_state=rng)

/export/home/software/anaconda3/lib/python3.7/site-packages/modin/pandas/base.py in sample(self, n, frac, replace, weights, random_state, axis)
   2481             if isinstance(random_state, int):
   2482                 random_num_gen = np.random.RandomState(random_state)
-> 2483             elif isinstance(random_state, np.random.randomState):
   2484                 random_num_gen = random_state
   2485             else:

AttributeError: module 'numpy.random' has no attribute 'randomState'
```



Discussion:
Hi @luoyunan thanks for posting this! I can reproduce the issue you are seeing on the current master.

As a temporary workaround until the next release, you can pass the integer value `42` instead of creating your own `RandomState` object.

Since it is a very minor fix and you went to the source to find it, would you like to open a PR that fixes this and adds a test case?
Hi @luoyunan thanks for posting this! I can reproduce the issue you are seeing on the current master.

As a temporary workaround until the next release, you can pass the integer value `42` instead of creating your own `RandomState` object.

Since it is a very minor fix and you went to the source to find it, would you like to open a PR that fixes this and adds a test case?

Resolving patch:
diff --git a/modin/pandas/base.py b/modin/pandas/base.py
--- a/modin/pandas/base.py
+++ b/modin/pandas/base.py
@@ -2480,7 +2480,7 @@ def sample(
             # random_state that is passed in
             if isinstance(random_state, int):
                 random_num_gen = np.random.RandomState(random_state)
-            elif isinstance(random_state, np.random.randomState):
+            elif isinstance(random_state, np.random.RandomState):
                 random_num_gen = random_state
             else:
                 # random_state must be an int or a numpy RandomState object


Test patch:
diff --git a/modin/pandas/test/test_dataframe.py b/modin/pandas/test/test_dataframe.py
--- a/modin/pandas/test/test_dataframe.py
+++ b/modin/pandas/test/test_dataframe.py
@@ -4950,6 +4950,16 @@ def test_sample(self, data, axis):
         pandas_result = pandas_df.sample(n=2, random_state=42, axis=axis)
         df_equals(modin_result, pandas_result)
 
+        # issue #1692, numpy RandomState object
+        # We must create a new random state for each iteration because the values that
+        # are selected will be impacted if the object has already been used.
+        random_state = np.random.RandomState(42)
+        modin_result = modin_df.sample(frac=0.5, random_state=random_state, axis=axis)
+
+        random_state = np.random.RandomState(42)
+        pandas_result = pandas_df.sample(frac=0.5, random_state=random_state, axis=axis)
+        df_equals(modin_result, pandas_result)
+
     def test_select_dtypes(self):
         frame_data = {
             "test1": list("abc"),