Skip to content

Commit

Permalink
REF: numpy.random-related imports
Browse files Browse the repository at this point in the history
  • Loading branch information
onshek committed Oct 13, 2020
1 parent 9cb3723 commit 669bf55
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 136 deletions.
20 changes: 10 additions & 10 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import warnings

import numpy as np
from numpy import random
from numpy.random import choice, normal, randint, uniform

from pandas.util._decorators import cache_readonly
import pandas.util._test_decorators as td
Expand Down Expand Up @@ -43,18 +43,18 @@ def setup_method(self, method):

n = 100
with tm.RNGContext(42):
gender = np.random.choice(["Male", "Female"], size=n)
classroom = np.random.choice(["A", "B", "C"], size=n)
gender = choice(["Male", "Female"], size=n)
classroom = choice(["A", "B", "C"], size=n)

self.hist_df = DataFrame(
{
"gender": gender,
"classroom": classroom,
"height": random.normal(66, 4, size=n),
"weight": random.normal(161, 32, size=n),
"category": random.randint(4, size=n),
"height": normal(66, 4, size=n),
"weight": normal(161, 32, size=n),
"category": randint(4, size=n),
"datetime": to_datetime(
random.randint(
randint(
self.start_date_to_int64,
self.end_date_to_int64,
size=n,
Expand All @@ -67,9 +67,9 @@ def setup_method(self, method):
self.tdf = tm.makeTimeDataFrame()
self.hexbin_df = DataFrame(
{
"A": np.random.uniform(size=20),
"B": np.random.uniform(size=20),
"C": np.arange(20) + np.random.uniform(size=20),
"A": uniform(size=20),
"B": uniform(size=20),
"C": np.arange(20) + uniform(size=20),
}
)

Expand Down
36 changes: 18 additions & 18 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import string

import numpy as np
from numpy import random
from numpy.random import choice, normal, rand, randint, randn, random
import pytest

import pandas.util._test_decorators as td
Expand All @@ -21,7 +21,7 @@ class TestDataFramePlots(TestPlotBase):
@pytest.mark.slow
def test_boxplot_legacy1(self):
df = DataFrame(
np.random.randn(6, 4),
randn(6, 4),
index=list(string.ascii_letters[:6]),
columns=["one", "two", "three", "four"],
)
Expand All @@ -45,7 +45,7 @@ def test_boxplot_legacy1(self):

@pytest.mark.slow
def test_boxplot_legacy2(self):
df = DataFrame(np.random.rand(10, 2), columns=["Col1", "Col2"])
df = DataFrame(rand(10, 2), columns=["Col1", "Col2"])
df["X"] = Series(["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"])
df["Y"] = Series(["A"] * 10)
with tm.assert_produces_warning(UserWarning):
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_boxplot_return_type_legacy(self):
import matplotlib as mpl # noqa

df = DataFrame(
np.random.randn(6, 4),
randn(6, 4),
index=list(string.ascii_letters[:6]),
columns=["one", "two", "three", "four"],
)
Expand Down Expand Up @@ -120,7 +120,7 @@ def _check_ax_limits(col, ax):
assert y_max >= col.max()

df = self.hist_df.copy()
df["age"] = np.random.randint(1, 20, df.shape[0])
df["age"] = randint(1, 20, df.shape[0])
# One full row
height_ax, weight_ax = df.boxplot(["height", "weight"], by="category")
_check_ax_limits(df["height"], height_ax)
Expand All @@ -141,13 +141,13 @@ def _check_ax_limits(col, ax):

@pytest.mark.slow
def test_boxplot_empty_column(self):
df = DataFrame(np.random.randn(20, 4))
df = DataFrame(randn(20, 4))
df.loc[:, 0] = np.nan
_check_plot_works(df.boxplot, return_type="axes")

@pytest.mark.slow
def test_figsize(self):
df = DataFrame(np.random.rand(10, 5), columns=["A", "B", "C", "D", "E"])
df = DataFrame(rand(10, 5), columns=["A", "B", "C", "D", "E"])
result = df.boxplot(return_type="axes", figsize=(12, 8))
assert result.figure.bbox_inches.width == 12
assert result.figure.bbox_inches.height == 8
Expand All @@ -163,8 +163,8 @@ def test_boxplot_numeric_data(self):
df = DataFrame(
{
"a": date_range("2012-01-01", periods=100),
"b": np.random.randn(100),
"c": np.random.randn(100) + 2,
"b": randn(100),
"c": randn(100) + 2,
"d": date_range("2012-01-01", periods=100).astype(str),
"e": date_range("2012-01-01", periods=100, tz="UTC"),
"f": timedelta_range("1 days", periods=100),
Expand All @@ -186,7 +186,7 @@ def test_boxplot_numeric_data(self):
)
def test_color_kwd(self, colors_kwd, expected):
# GH: 26214
df = DataFrame(random.rand(10, 2))
df = DataFrame(rand(10, 2))
result = df.boxplot(color=colors_kwd, return_type="dict")
for k, v in expected.items():
assert result[k][0].get_color() == v
Expand All @@ -197,7 +197,7 @@ def test_color_kwd(self, colors_kwd, expected):
)
def test_color_kwd_errors(self, dict_colors, msg):
# GH: 26214
df = DataFrame(random.rand(10, 2))
df = DataFrame(rand(10, 2))
with pytest.raises(ValueError, match=msg):
df.boxplot(color=dict_colors, return_type="dict")

Expand All @@ -212,7 +212,7 @@ def test_color_kwd_errors(self, dict_colors, msg):
)
def test_specified_props_kwd(self, props, expected):
# GH 30346
df = DataFrame({k: np.random.random(100) for k in "ABC"})
df = DataFrame({k: random(100) for k in "ABC"})
kwd = {props: dict(color="C1")}
result = df.boxplot(return_type="dict", **kwd)

Expand All @@ -233,7 +233,7 @@ def test_boxplot_legacy1(self):
@pytest.mark.slow
def test_boxplot_legacy2(self):
tuples = zip(string.ascii_letters[:10], range(10))
df = DataFrame(np.random.rand(10, 3), index=MultiIndex.from_tuples(tuples))
df = DataFrame(rand(10, 3), index=MultiIndex.from_tuples(tuples))
grouped = df.groupby(level=1)
with tm.assert_produces_warning(UserWarning):
axes = _check_plot_works(grouped.boxplot, return_type="axes")
Expand All @@ -245,7 +245,7 @@ def test_boxplot_legacy2(self):
@pytest.mark.slow
def test_boxplot_legacy3(self):
tuples = zip(string.ascii_letters[:10], range(10))
df = DataFrame(np.random.rand(10, 3), index=MultiIndex.from_tuples(tuples))
df = DataFrame(rand(10, 3), index=MultiIndex.from_tuples(tuples))
grouped = df.unstack(level=1).groupby(level=0, axis=1)
with tm.assert_produces_warning(UserWarning):
axes = _check_plot_works(grouped.boxplot, return_type="axes")
Expand All @@ -256,10 +256,10 @@ def test_boxplot_legacy3(self):
@pytest.mark.slow
def test_grouped_plot_fignums(self):
n = 10
weight = Series(np.random.normal(166, 20, size=n))
height = Series(np.random.normal(60, 10, size=n))
weight = Series(normal(166, 20, size=n))
height = Series(normal(60, 10, size=n))
with tm.RNGContext(42):
gender = np.random.choice(["male", "female"], size=n)
gender = choice(["male", "female"], size=n)
df = DataFrame({"height": height, "weight": weight, "gender": gender})
gb = df.groupby("gender")

Expand Down Expand Up @@ -293,7 +293,7 @@ def test_grouped_box_return_type(self):
self._check_box_return_type(result, "dict", expected_keys=["Male", "Female"])

columns2 = "X B C D A G Y N Q O".split()
df2 = DataFrame(random.randn(50, 10), columns=columns2)
df2 = DataFrame(randn(50, 10), columns=columns2)
categories2 = "A B C D E F G H I J".split()
df2["category"] = categories2 * 5

Expand Down

0 comments on commit 669bf55

Please sign in to comment.