diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 728ffc6f85ba4..3e16ec134db46 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -6,7 +6,6 @@ import warnings import numpy as np -from numpy.random import rand, randint, randn import pytest from pandas.compat import is_platform_windows @@ -126,15 +125,15 @@ def _is_py3_complex_incompat(result, expected): @pytest.fixture(params=list(range(5))) def lhs(request): - nan_df1 = DataFrame(rand(10, 5)) + nan_df1 = DataFrame(np.random.rand(10, 5)) nan_df1[nan_df1 > 0.5] = np.nan opts = ( - DataFrame(randn(10, 5)), - Series(randn(5)), + DataFrame(np.random.randn(10, 5)), + Series(np.random.randn(5)), Series([1, 2, np.nan, np.nan, 5]), nan_df1, - randn(), + np.random.randn(), ) return opts[request.param] @@ -455,7 +454,7 @@ def test_frame_invert(self): # ~ ## # frame # float always raises - lhs = DataFrame(randn(5, 2)) + lhs = DataFrame(np.random.randn(5, 2)) if self.engine == "numexpr": msg = "couldn't find matching opcode for 'invert_dd'" with pytest.raises(NotImplementedError, match=msg): @@ -466,7 +465,7 @@ def test_frame_invert(self): result = pd.eval(expr, engine=self.engine, parser=self.parser) # int raises on numexpr - lhs = DataFrame(randint(5, size=(5, 2))) + lhs = DataFrame(np.random.randint(5, size=(5, 2))) if self.engine == "numexpr": msg = "couldn't find matching opcode for 'invert" with pytest.raises(NotImplementedError, match=msg): @@ -477,13 +476,13 @@ def test_frame_invert(self): tm.assert_frame_equal(expect, result) # bool always works - lhs = DataFrame(rand(5, 2) > 0.5) + lhs = DataFrame(np.random.rand(5, 2) > 0.5) expect = ~lhs result = pd.eval(expr, engine=self.engine, parser=self.parser) tm.assert_frame_equal(expect, result) # object raises - lhs = DataFrame({"b": ["a", 1, 2.0], "c": rand(3) > 0.5}) + lhs = DataFrame({"b": ["a", 1, 2.0], "c": np.random.rand(3) > 0.5}) if self.engine == "numexpr": with pytest.raises(ValueError, match="unknown type object"): result = pd.eval(expr, engine=self.engine, parser=self.parser) @@ -498,7 +497,7 @@ def test_series_invert(self): # series # float raises - lhs = Series(randn(5)) + lhs = Series(np.random.randn(5)) if self.engine == "numexpr": msg = "couldn't find matching opcode for 'invert_dd'" with pytest.raises(NotImplementedError, match=msg): @@ -509,7 +508,7 @@ def test_series_invert(self): result = pd.eval(expr, engine=self.engine, parser=self.parser) # int raises on numexpr - lhs = Series(randint(5, size=5)) + lhs = Series(np.random.randint(5, size=5)) if self.engine == "numexpr": msg = "couldn't find matching opcode for 'invert" with pytest.raises(NotImplementedError, match=msg): @@ -520,7 +519,7 @@ def test_series_invert(self): tm.assert_series_equal(expect, result) # bool - lhs = Series(rand(5) > 0.5) + lhs = Series(np.random.rand(5) > 0.5) expect = ~lhs result = pd.eval(expr, engine=self.engine, parser=self.parser) tm.assert_series_equal(expect, result) @@ -543,19 +542,19 @@ def test_frame_negate(self): expr = self.ex("-") # float - lhs = DataFrame(randn(5, 2)) + lhs = DataFrame(np.random.randn(5, 2)) expect = -lhs result = pd.eval(expr, engine=self.engine, parser=self.parser) tm.assert_frame_equal(expect, result) # int - lhs = DataFrame(randint(5, size=(5, 2))) + lhs = DataFrame(np.random.randint(5, size=(5, 2))) expect = -lhs result = pd.eval(expr, engine=self.engine, parser=self.parser) tm.assert_frame_equal(expect, result) # bool doesn't work with numexpr but works elsewhere - lhs = DataFrame(rand(5, 2) > 0.5) + lhs = DataFrame(np.random.rand(5, 2) > 0.5) if self.engine == "numexpr": msg = "couldn't find matching opcode for 'neg_bb'" with pytest.raises(NotImplementedError, match=msg): @@ -569,19 +568,19 @@ def test_series_negate(self): expr = self.ex("-") # float - lhs = Series(randn(5)) + lhs = Series(np.random.randn(5)) expect = -lhs result = pd.eval(expr, engine=self.engine, parser=self.parser) tm.assert_series_equal(expect, result) # int - lhs = Series(randint(5, size=5)) + lhs = Series(np.random.randint(5, size=5)) expect = -lhs result = pd.eval(expr, engine=self.engine, parser=self.parser) tm.assert_series_equal(expect, result) # bool doesn't work with numexpr but works elsewhere - lhs = Series(rand(5) > 0.5) + lhs = Series(np.random.rand(5) > 0.5) if self.engine == "numexpr": msg = "couldn't find matching opcode for 'neg_bb'" with pytest.raises(NotImplementedError, match=msg): @@ -595,11 +594,11 @@ def test_series_negate(self): "lhs", [ # Float - DataFrame(randn(5, 2)), + DataFrame(np.random.randn(5, 2)), # Int - DataFrame(randint(5, size=(5, 2))), + DataFrame(np.random.randint(5, size=(5, 2))), # bool doesn't work with numexpr but works elsewhere - DataFrame(rand(5, 2) > 0.5), + DataFrame(np.random.rand(5, 2) > 0.5), ], ) def test_frame_pos(self, lhs): @@ -613,11 +612,11 @@ def test_frame_pos(self, lhs): "lhs", [ # Float - Series(randn(5)), + Series(np.random.randn(5)), # Int - Series(randint(5, size=5)), + Series(np.random.randint(5, size=5)), # bool doesn't work with numexpr but works elsewhere - Series(rand(5) > 0.5), + Series(np.random.rand(5) > 0.5), ], ) def test_series_pos(self, lhs): @@ -688,7 +687,7 @@ def test_disallow_scalar_bool_ops(self): exprs += ("2 * x > 2 or 1 and 2",) exprs += ("2 * df > 3 and 1 or a",) - x, a, b, df = np.random.randn(3), 1, 2, DataFrame(randn(3, 2)) # noqa + x, a, b, df = np.random.randn(3), 1, 2, DataFrame(np.random.randn(3, 2)) # noqa for ex in exprs: msg = "cannot evaluate scalar only bool ops|'BoolOp' nodes are not" with pytest.raises(NotImplementedError, match=msg): @@ -909,7 +908,7 @@ def test_frame_comparison(self, engine, parser, r_idx_type, c_idx_type): res = pd.eval("df < 2", engine=engine, parser=parser) tm.assert_frame_equal(res, df < 2) - df3 = DataFrame(randn(*df.shape), index=df.index, columns=df.columns) + df3 = DataFrame(np.random.randn(*df.shape), index=df.index, columns=df.columns) res = pd.eval("df < df3", engine=engine, parser=parser) tm.assert_frame_equal(res, df < df3) @@ -1089,8 +1088,8 @@ def test_complex_series_frame_alignment(self, engine, parser, r1, c1, r2, c2): tm.assert_frame_equal(res, expected) def test_performance_warning_for_poor_alignment(self, engine, parser): - df = DataFrame(randn(1000, 10)) - s = Series(randn(10000)) + df = DataFrame(np.random.randn(1000, 10)) + s = Series(np.random.randn(10000)) if engine == "numexpr": seen = PerformanceWarning else: @@ -1099,17 +1098,17 @@ def test_performance_warning_for_poor_alignment(self, engine, parser): with tm.assert_produces_warning(seen): pd.eval("df + s", engine=engine, parser=parser) - s = Series(randn(1000)) + s = Series(np.random.randn(1000)) with tm.assert_produces_warning(False): pd.eval("df + s", engine=engine, parser=parser) - df = DataFrame(randn(10, 10000)) - s = Series(randn(10000)) + df = DataFrame(np.random.randn(10, 10000)) + s = Series(np.random.randn(10000)) with tm.assert_produces_warning(False): pd.eval("df + s", engine=engine, parser=parser) - df = DataFrame(randn(10, 10)) - s = Series(randn(10000)) + df = DataFrame(np.random.randn(10, 10)) + s = Series(np.random.randn(10000)) is_python_engine = engine == "python" @@ -1206,8 +1205,8 @@ def test_bool_ops_with_constants(self, rhs, lhs, op): assert res == exp def test_4d_ndarray_fails(self): - x = randn(3, 4, 5, 6) - y = Series(randn(10)) + x = np.random.randn(3, 4, 5, 6) + y = Series(np.random.randn(10)) msg = "N-dimensional objects, where N > 2, are not supported with eval" with pytest.raises(NotImplementedError, match=msg): self.eval("x + y", local_dict={"x": x, "y": y}) @@ -1217,7 +1216,7 @@ def test_constant(self): assert x == 1 def test_single_variable(self): - df = DataFrame(randn(10, 2)) + df = DataFrame(np.random.randn(10, 2)) df2 = self.eval("df", local_dict={"df": df}) tm.assert_frame_equal(df, df2) @@ -1574,7 +1573,7 @@ def test_nested_period_index_subscript_expression(self): tm.assert_frame_equal(r, e) def test_date_boolean(self): - df = DataFrame(randn(5, 3)) + df = DataFrame(np.random.randn(5, 3)) df["dates1"] = date_range("1/1/2012", periods=5) res = self.eval( "df.dates1 < 20130101", @@ -1859,7 +1858,7 @@ class TestMathNumExprPython(TestMathPythonPython): parser = "python" -_var_s = randn(10) +_var_s = np.random.randn(10) class TestScope: diff --git a/pandas/tests/indexing/multiindex/test_insert.py b/pandas/tests/indexing/multiindex/test_insert.py index 42922c3deeee4..9f5ad90d36e03 100644 --- a/pandas/tests/indexing/multiindex/test_insert.py +++ b/pandas/tests/indexing/multiindex/test_insert.py @@ -1,4 +1,4 @@ -from numpy.random import randn +import numpy as np from pandas import DataFrame, MultiIndex, Series import pandas._testing as tm @@ -14,7 +14,7 @@ def test_setitem_mixed_depth(self): tuples = sorted(zip(*arrays)) index = MultiIndex.from_tuples(tuples) - df = DataFrame(randn(4, 6), columns=index) + df = DataFrame(np.random.randn(4, 6), columns=index) result = df.copy() expected = df.copy() diff --git a/pandas/tests/indexing/multiindex/test_setitem.py b/pandas/tests/indexing/multiindex/test_setitem.py index b58b81d5aa1b3..059f8543104a7 100644 --- a/pandas/tests/indexing/multiindex/test_setitem.py +++ b/pandas/tests/indexing/multiindex/test_setitem.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest import pandas as pd @@ -311,7 +310,9 @@ def test_frame_getitem_setitem_multislice(self): tm.assert_frame_equal(df, result) def test_frame_setitem_multi_column(self): - df = DataFrame(randn(10, 4), columns=[["a", "a", "b", "b"], [0, 1, 0, 1]]) + df = DataFrame( + np.random.randn(10, 4), columns=[["a", "a", "b", "b"], [0, 1, 0, 1]] + ) cp = df.copy() cp["a"] = cp["b"] diff --git a/pandas/tests/indexing/multiindex/test_sorted.py b/pandas/tests/indexing/multiindex/test_sorted.py index bafe5068e1418..8a013c769f2cc 100644 --- a/pandas/tests/indexing/multiindex/test_sorted.py +++ b/pandas/tests/indexing/multiindex/test_sorted.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest from pandas import DataFrame, MultiIndex, Series @@ -115,7 +114,7 @@ def test_series_getitem_not_sorted(self): ] tuples = zip(*arrays) index = MultiIndex.from_tuples(tuples) - s = Series(randn(8), index=index) + s = Series(np.random.randn(8), index=index) arrays = [np.array(x) for x in zip(*index.values)] diff --git a/pandas/tests/io/test_clipboard.py b/pandas/tests/io/test_clipboard.py index a454d3b855cdf..569bc8a04862e 100644 --- a/pandas/tests/io/test_clipboard.py +++ b/pandas/tests/io/test_clipboard.py @@ -1,7 +1,6 @@ from textwrap import dedent import numpy as np -from numpy.random import randint import pytest import pandas as pd @@ -54,7 +53,7 @@ def df(request): return tm.makeCustomDataframe( max_rows + 1, 3, - data_gen_f=lambda *args: randint(2), + data_gen_f=lambda *args: np.random.randint(2), c_idx_type="s", r_idx_type="i", c_idx_names=[None], @@ -95,7 +94,7 @@ def df(request): return tm.makeCustomDataframe( 5, 3, - data_gen_f=lambda *args: randint(2), + data_gen_f=lambda *args: np.random.randint(2), c_idx_type="s", r_idx_type="i", c_idx_names=[None], diff --git a/pandas/tests/io/test_html.py b/pandas/tests/io/test_html.py index 59034e9f3d807..f929d4ac31484 100644 --- a/pandas/tests/io/test_html.py +++ b/pandas/tests/io/test_html.py @@ -7,7 +7,6 @@ from urllib.error import URLError import numpy as np -from numpy.random import rand import pytest from pandas.compat import is_platform_windows @@ -110,7 +109,7 @@ def test_to_html_compat(self): tm.makeCustomDataframe( 4, 3, - data_gen_f=lambda *args: rand(), + data_gen_f=lambda *args: np.random.rand(), c_idx_names=False, r_idx_names=False, ) diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 2a6bd97c93b8e..c04b70f3c2953 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -2,7 +2,6 @@ import warnings import numpy as np -from numpy import random from pandas.util._decorators import cache_readonly import pandas.util._test_decorators as td @@ -50,11 +49,11 @@ def setup_method(self, method): { "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": np.random.normal(66, 4, size=n), + "weight": np.random.normal(161, 32, size=n), + "category": np.random.randint(4, size=n), "datetime": to_datetime( - random.randint( + np.random.randint( self.start_date_to_int64, self.end_date_to_int64, size=n, diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 0a096acc9fa6d..dc2e9e1e8d15f 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -2,7 +2,6 @@ import string import numpy as np -from numpy import random import pytest import pandas.util._test_decorators as td @@ -186,7 +185,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(np.random.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 @@ -197,7 +196,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(np.random.rand(10, 2)) with pytest.raises(ValueError, match=msg): df.boxplot(color=dict_colors, return_type="dict") @@ -293,7 +292,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(np.random.randn(50, 10), columns=columns2) categories2 = "A B C D E F G H I J".split() df2["category"] = categories2 * 5 diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index ba59fc1a3cc3f..e6a61d35365a3 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -6,7 +6,6 @@ import warnings import numpy as np -from numpy.random import rand, randn import pytest import pandas.util._test_decorators as td @@ -170,7 +169,7 @@ def test_integer_array_plot(self): def test_mpl2_color_cycle_str(self): # GH 15516 - df = DataFrame(randn(10, 3), columns=["a", "b", "c"]) + df = DataFrame(np.random.randn(10, 3), columns=["a", "b", "c"]) colors = ["C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9"] with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always", "MatplotlibDeprecationWarning") @@ -198,7 +197,7 @@ def test_rgb_tuple_color(self): _check_plot_works(df.plot, x="x", y="y", color=(1, 0, 0, 0.5)) def test_color_empty_string(self): - df = DataFrame(randn(10, 2)) + df = DataFrame(np.random.randn(10, 2)) with pytest.raises(ValueError): df.plot(color="") @@ -243,14 +242,14 @@ def test_nonnumeric_exclude(self): @pytest.mark.slow def test_implicit_label(self): - df = DataFrame(randn(10, 3), columns=["a", "b", "c"]) + df = DataFrame(np.random.randn(10, 3), columns=["a", "b", "c"]) ax = df.plot(x="a", y="b") self._check_text_labels(ax.xaxis.get_label(), "a") @pytest.mark.slow def test_donot_overwrite_index_name(self): # GH 8494 - df = DataFrame(randn(2, 2), columns=["a", "b"]) + df = DataFrame(np.random.randn(2, 2), columns=["a", "b"]) df.index.name = "NAME" df.plot(y="b", label="LABEL") assert df.index.name == "NAME" @@ -813,7 +812,7 @@ def test_subplots_dup_columns(self): def test_negative_log(self): df = -DataFrame( - rand(6, 4), + np.random.rand(6, 4), index=list(string.ascii_letters[:6]), columns=["x", "y", "z", "four"], ) @@ -832,15 +831,20 @@ def _compare_stacked_y_cood(self, normal_lines, stacked_lines): def test_line_area_stacked(self): with tm.RNGContext(42): - df = DataFrame(rand(6, 4), columns=["w", "x", "y", "z"]) + df = DataFrame(np.random.rand(6, 4), columns=["w", "x", "y", "z"]) neg_df = -df # each column has either positive or negative value sep_df = DataFrame( - {"w": rand(6), "x": rand(6), "y": -rand(6), "z": -rand(6)} + { + "w": np.random.rand(6), + "x": np.random.rand(6), + "y": -np.random.rand(6), + "z": -np.random.rand(6), + } ) # each column has positive-negative mixed value mixed_df = DataFrame( - randn(6, 4), + np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=["w", "x", "y", "z"], ) @@ -908,7 +912,7 @@ def test_line_area_nan_df(self): tm.assert_numpy_array_equal(ax.lines[1].get_ydata(), expected2) def test_line_lim(self): - df = DataFrame(rand(6, 3), columns=["x", "y", "z"]) + df = DataFrame(np.random.rand(6, 3), columns=["x", "y", "z"]) ax = df.plot() xmin, xmax = ax.get_xlim() lines = ax.get_lines() @@ -932,7 +936,7 @@ def test_line_lim(self): assert xmax >= lines[0].get_data()[0][-1] def test_area_lim(self): - df = DataFrame(rand(6, 4), columns=["x", "y", "z", "four"]) + df = DataFrame(np.random.rand(6, 4), columns=["x", "y", "z", "four"]) neg_df = -df for stacked in [True, False]: @@ -954,7 +958,7 @@ def test_bar_colors(self): default_colors = self._unpack_cycler(plt.rcParams) - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) ax = df.plot.bar() self._check_colors(ax.patches[::5], facecolors=default_colors[:5]) tm.close() @@ -1004,7 +1008,7 @@ def test_bar_user_colors(self): @pytest.mark.slow def test_bar_linewidth(self): - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) # regular ax = df.plot.bar(linewidth=2) @@ -1025,7 +1029,7 @@ def test_bar_linewidth(self): @pytest.mark.slow def test_bar_barwidth(self): - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) width = 0.9 @@ -1063,7 +1067,7 @@ def test_bar_barwidth(self): @pytest.mark.slow def test_bar_barwidth_position(self): - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) self._check_bar_alignment( df, kind="bar", stacked=False, width=0.9, position=0.2 ) @@ -1084,7 +1088,7 @@ def test_bar_barwidth_position(self): @pytest.mark.slow def test_bar_barwidth_position_int(self): # GH 12979 - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) for w in [1, 1.0]: ax = df.plot.bar(stacked=True, width=w) @@ -1103,7 +1107,7 @@ def test_bar_barwidth_position_int(self): @pytest.mark.slow def test_bar_bottom_left(self): - df = DataFrame(rand(5, 5)) + df = DataFrame(np.random.rand(5, 5)) ax = df.plot.bar(stacked=False, bottom=1) result = [p.get_y() for p in ax.patches] assert result == [1] * 25 @@ -1179,7 +1183,7 @@ def test_bar_categorical(self): @pytest.mark.slow def test_plot_scatter(self): df = DataFrame( - randn(6, 4), + np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=["x", "y", "z", "four"], ) @@ -1291,7 +1295,7 @@ def test_plot_scatter_with_categorical_data(self, x, y): @pytest.mark.slow def test_plot_scatter_with_c(self): df = DataFrame( - randn(6, 4), + np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=["x", "y", "z", "four"], ) @@ -1394,7 +1398,7 @@ def test_scatter_colorbar_different_cmap(self): @pytest.mark.slow def test_plot_bar(self): df = DataFrame( - randn(6, 4), + np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=["one", "two", "three", "four"], ) @@ -1407,7 +1411,9 @@ def test_plot_bar(self): _check_plot_works(df.plot.bar, stacked=True) df = DataFrame( - randn(10, 15), index=list(string.ascii_letters[:10]), columns=range(15) + np.random.randn(10, 15), + index=list(string.ascii_letters[:10]), + columns=range(15), ) _check_plot_works(df.plot.bar) @@ -1523,7 +1529,7 @@ def test_bar_subplots_center(self): @pytest.mark.slow def test_bar_align_single_column(self): - df = DataFrame(randn(5)) + df = DataFrame(np.random.randn(5)) self._check_bar_alignment(df, kind="bar", stacked=False) self._check_bar_alignment(df, kind="bar", stacked=True) self._check_bar_alignment(df, kind="barh", stacked=False) @@ -1641,7 +1647,7 @@ def test_boxplot_vertical(self): @pytest.mark.slow def test_boxplot_return_type(self): df = DataFrame( - randn(6, 4), + np.random.randn(6, 4), index=list(string.ascii_letters[:6]), columns=["one", "two", "three", "four"], ) @@ -1683,7 +1689,7 @@ def test_boxplot_subplots_return_type(self): @pytest.mark.slow @td.skip_if_no_scipy def test_kde_df(self): - df = DataFrame(randn(100, 4)) + df = DataFrame(np.random.randn(100, 4)) ax = _check_plot_works(df.plot, kind="kde") expected = [pprint_thing(c) for c in df.columns] self._check_legend_labels(ax, labels=expected) @@ -1710,7 +1716,7 @@ def test_kde_missing_vals(self): def test_hist_df(self): from matplotlib.patches import Rectangle - df = DataFrame(randn(100, 4)) + df = DataFrame(np.random.randn(100, 4)) series = df[0] ax = _check_plot_works(df.plot.hist) @@ -1918,16 +1924,16 @@ def test_hist_df_coord(self): @pytest.mark.slow def test_plot_int_columns(self): - df = DataFrame(randn(100, 4)).cumsum() + df = DataFrame(np.random.randn(100, 4)).cumsum() _check_plot_works(df.plot, legend=True) @pytest.mark.slow def test_df_legend_labels(self): kinds = ["line", "bar", "barh", "kde", "area", "hist"] - df = DataFrame(rand(3, 3), columns=["a", "b", "c"]) - df2 = DataFrame(rand(3, 3), columns=["d", "e", "f"]) - df3 = DataFrame(rand(3, 3), columns=["g", "h", "i"]) - df4 = DataFrame(rand(3, 3), columns=["j", "k", "l"]) + df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"]) + df2 = DataFrame(np.random.rand(3, 3), columns=["d", "e", "f"]) + df3 = DataFrame(np.random.rand(3, 3), columns=["g", "h", "i"]) + df4 = DataFrame(np.random.rand(3, 3), columns=["j", "k", "l"]) for kind in kinds: @@ -1956,9 +1962,9 @@ def test_df_legend_labels(self): # Time Series ind = date_range("1/1/2014", periods=3) - df = DataFrame(randn(3, 3), columns=["a", "b", "c"], index=ind) - df2 = DataFrame(randn(3, 3), columns=["d", "e", "f"], index=ind) - df3 = DataFrame(randn(3, 3), columns=["g", "h", "i"], index=ind) + df = DataFrame(np.random.randn(3, 3), columns=["a", "b", "c"], index=ind) + df2 = DataFrame(np.random.randn(3, 3), columns=["d", "e", "f"], index=ind) + df3 = DataFrame(np.random.randn(3, 3), columns=["g", "h", "i"], index=ind) ax = df.plot(legend=True, secondary_y="b") self._check_legend_labels(ax, labels=["a", "b (right)", "c"]) ax = df2.plot(legend=False, ax=ax) @@ -2012,7 +2018,7 @@ def test_missing_marker_multi_plots_on_same_ax(self): def test_legend_name(self): multi = DataFrame( - randn(4, 4), + np.random.randn(4, 4), columns=[np.array(["a", "a", "b", "b"]), np.array(["x", "y", "x", "y"])], ) multi.columns.names = ["group", "individual"] @@ -2021,7 +2027,7 @@ def test_legend_name(self): leg_title = ax.legend_.get_title() self._check_text_labels(leg_title, "group,individual") - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) ax = df.plot(legend=True, ax=ax) leg_title = ax.legend_.get_title() self._check_text_labels(leg_title, "group,individual") @@ -2038,7 +2044,7 @@ def test_legend_name(self): @pytest.mark.slow def test_no_legend(self): kinds = ["line", "bar", "barh", "kde", "area", "hist"] - df = DataFrame(rand(3, 3), columns=["a", "b", "c"]) + df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"]) for kind in kinds: @@ -2051,7 +2057,7 @@ def test_style_by_column(self): fig = plt.gcf() - df = DataFrame(randn(100, 3)) + df = DataFrame(np.random.randn(100, 3)) for markers in [ {0: "^", 1: "+", 2: "o"}, {0: "^", 1: "+"}, @@ -2078,7 +2084,7 @@ def test_line_colors(self): from matplotlib import cm custom_colors = "rgcby" - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) ax = df.plot(color=custom_colors) self._check_colors(ax.get_lines(), linecolors=custom_colors) @@ -2131,7 +2137,7 @@ def test_line_colors_and_styles_subplots(self): default_colors = self._unpack_cycler(self.plt.rcParams) - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) axes = df.plot(subplots=True) for ax, c in zip(axes, list(default_colors)): @@ -2200,7 +2206,7 @@ def test_area_colors(self): from matplotlib.collections import PolyCollection custom_colors = "rgcby" - df = DataFrame(rand(5, 5)) + df = DataFrame(np.random.rand(5, 5)) ax = df.plot.area(color=custom_colors) self._check_colors(ax.get_lines(), linecolors=custom_colors) @@ -2243,7 +2249,7 @@ def test_area_colors(self): def test_hist_colors(self): default_colors = self._unpack_cycler(self.plt.rcParams) - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) ax = df.plot.hist() self._check_colors(ax.patches[::10], facecolors=default_colors[:5]) tm.close() @@ -2280,7 +2286,7 @@ def test_kde_colors(self): from matplotlib import cm custom_colors = "rgcby" - df = DataFrame(rand(5, 5)) + df = DataFrame(np.random.rand(5, 5)) ax = df.plot.kde(color=custom_colors) self._check_colors(ax.get_lines(), linecolors=custom_colors) @@ -2302,7 +2308,7 @@ def test_kde_colors_and_styles_subplots(self): default_colors = self._unpack_cycler(self.plt.rcParams) - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) axes = df.plot(kind="kde", subplots=True) for ax, c in zip(axes, list(default_colors)): @@ -2370,7 +2376,7 @@ def _check_colors(bp, box_c, whiskers_c, medians_c, caps_c="k", fliers_c=None): default_colors = self._unpack_cycler(self.plt.rcParams) - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) bp = df.plot.box(return_type="dict") _check_colors(bp, default_colors[0], default_colors[0], default_colors[2]) tm.close() @@ -2444,7 +2450,7 @@ def test_default_color_cycle(self): colors = list("rgbk") plt.rcParams["axes.prop_cycle"] = cycler.cycler("color", colors) - df = DataFrame(randn(5, 3)) + df = DataFrame(np.random.randn(5, 3)) ax = df.plot() expected = self._unpack_cycler(plt.rcParams)[:3] @@ -2484,7 +2490,7 @@ def test_all_invalid_plot_data(self): @pytest.mark.slow def test_partially_invalid_plot_data(self): with tm.RNGContext(42): - df = DataFrame(randn(10, 2), dtype=object) + df = DataFrame(np.random.randn(10, 2), dtype=object) df[np.random.rand(df.shape[0]) > 0.5] = "a" for kind in plotting.PlotAccessor._common_kinds: @@ -2495,14 +2501,14 @@ def test_partially_invalid_plot_data(self): with tm.RNGContext(42): # area plot doesn't support positive/negative mixed data kinds = ["area"] - df = DataFrame(rand(10, 2), dtype=object) + df = DataFrame(np.random.rand(10, 2), dtype=object) df[np.random.rand(df.shape[0]) > 0.5] = "a" for kind in kinds: with pytest.raises(TypeError): df.plot(kind=kind) def test_invalid_kind(self): - df = DataFrame(randn(10, 2)) + df = DataFrame(np.random.randn(10, 2)) with pytest.raises(ValueError): df.plot(kind="aasdf") @@ -3208,7 +3214,7 @@ def test_df_grid_settings(self): ) def test_invalid_colormap(self): - df = DataFrame(randn(3, 2), columns=["A", "B"]) + df = DataFrame(np.random.randn(3, 2), columns=["A", "B"]) with pytest.raises(ValueError): df.plot(colormap="invalid_colormap") @@ -3219,11 +3225,11 @@ def test_plain_axes(self): # a plain Axes object (GH11556) fig, ax = self.plt.subplots() fig.add_axes([0.2, 0.2, 0.2, 0.2]) - Series(rand(10)).plot(ax=ax) + Series(np.random.rand(10)).plot(ax=ax) # supplied ax itself is a plain Axes, but because the cmap keyword # a new ax is created for the colorbar -> also multiples axes (GH11520) - df = DataFrame({"a": randn(8), "b": randn(8)}) + df = DataFrame({"a": np.random.randn(8), "b": np.random.randn(8)}) fig = self.plt.figure() ax = fig.add_axes((0, 0, 1, 1)) df.plot(kind="scatter", ax=ax, x="a", y="b", c="a", cmap="hsv") @@ -3234,15 +3240,15 @@ def test_plain_axes(self): divider = make_axes_locatable(ax) cax = divider.append_axes("right", size="5%", pad=0.05) - Series(rand(10)).plot(ax=ax) - Series(rand(10)).plot(ax=cax) + Series(np.random.rand(10)).plot(ax=ax) + Series(np.random.rand(10)).plot(ax=cax) fig, ax = self.plt.subplots() from mpl_toolkits.axes_grid1.inset_locator import inset_axes iax = inset_axes(ax, width="30%", height=1.0, loc=3) - Series(rand(10)).plot(ax=ax) - Series(rand(10)).plot(ax=iax) + Series(np.random.rand(10)).plot(ax=ax) + Series(np.random.rand(10)).plot(ax=iax) def test_passed_bar_colors(self): import matplotlib as mpl diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index d9a58e808661b..9775218e0dbf6 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -1,7 +1,6 @@ """ Test cases for .hist method """ import numpy as np -from numpy.random import randn import pytest import pandas.util._test_decorators as td @@ -103,8 +102,8 @@ def test_hist_layout_with_by(self): def test_hist_no_overlap(self): from matplotlib.pyplot import gcf, subplot - x = Series(randn(2)) - y = Series(randn(2)) + x = Series(np.random.randn(2)) + y = Series(np.random.randn(2)) subplot(121) x.hist() subplot(122) @@ -163,7 +162,7 @@ def test_hist_df_legacy(self): _check_plot_works(self.hist_df.hist) # make sure layout is handled - df = DataFrame(randn(100, 2)) + df = DataFrame(np.random.randn(100, 2)) df[2] = to_datetime( np.random.randint( self.start_date_to_int64, @@ -178,11 +177,11 @@ def test_hist_df_legacy(self): assert not axes[1, 1].get_visible() _check_plot_works(df[[2]].hist) - df = DataFrame(randn(100, 1)) + df = DataFrame(np.random.randn(100, 1)) _check_plot_works(df.hist) # make sure layout is handled - df = DataFrame(randn(100, 5)) + df = DataFrame(np.random.randn(100, 5)) df[5] = to_datetime( np.random.randint( self.start_date_to_int64, @@ -269,7 +268,7 @@ def test_hist_non_numerical_or_datetime_raises(self): @pytest.mark.slow def test_hist_layout(self): - df = DataFrame(randn(100, 2)) + df = DataFrame(np.random.randn(100, 2)) df[2] = to_datetime( np.random.randint( self.start_date_to_int64, @@ -404,7 +403,7 @@ def test_grouped_hist_legacy(self): from pandas.plotting._matplotlib.hist import _grouped_hist - df = DataFrame(randn(500, 1), columns=["A"]) + df = DataFrame(np.random.randn(500, 1), columns=["A"]) df["B"] = to_datetime( np.random.randint( self.start_date_to_int64, diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 2838bef2a10b0..f37d83cd0783e 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -1,8 +1,6 @@ """ Test cases for misc plot functions """ import numpy as np -from numpy import random -from numpy.random import randn import pytest import pandas.util._test_decorators as td @@ -101,7 +99,7 @@ def test_scatter_matrix_axis(self): scatter_matrix = plotting.scatter_matrix with tm.RNGContext(42): - df = DataFrame(randn(100, 3)) + df = DataFrame(np.random.randn(100, 3)) # we are plotting multiples on a sub-plot with tm.assert_produces_warning( @@ -166,9 +164,9 @@ def test_andrews_curves(self, iris): length = 10 df = DataFrame( { - "A": random.rand(length), - "B": random.rand(length), - "C": random.rand(length), + "A": np.random.rand(length), + "B": np.random.rand(length), + "C": np.random.rand(length), "Name": ["A"] * length, } ) @@ -353,11 +351,11 @@ def test_get_standard_colors_random_seed(self): # GH17525 df = DataFrame(np.zeros((10, 10))) - # Make sure that the random seed isn't reset by get_standard_colors + # Make sure that the np.random.seed isn't reset by get_standard_colors plotting.parallel_coordinates(df, 0) - rand1 = random.random() + rand1 = np.random.random() plotting.parallel_coordinates(df, 0) - rand2 = random.random() + rand2 = np.random.random() assert rand1 != rand2 # Make sure it produces the same colors every time it's called diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 271cf65433afe..777bc914069a6 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -5,7 +5,6 @@ from itertools import chain import numpy as np -from numpy.random import randn import pytest import pandas.util._test_decorators as td @@ -59,7 +58,7 @@ def test_plot(self): _check_plot_works(self.series[:5].plot, kind=kind) _check_plot_works(self.series[:10].plot.barh) - ax = _check_plot_works(Series(randn(10)).plot.bar, color="black") + ax = _check_plot_works(Series(np.random.randn(10)).plot.bar, color="black") self._check_colors([ax.patches[0]], facecolors=["black"]) # GH 6951 @@ -267,7 +266,7 @@ def test_bar_user_colors(self): assert result == expected def test_rotation(self): - df = DataFrame(randn(5, 5)) + df = DataFrame(np.random.randn(5, 5)) # Default rot 0 _, ax = self.plt.subplots() axes = df.plot(ax=ax) @@ -282,7 +281,7 @@ def test_irregular_datetime(self): rng = date_range("1/1/2000", "3/1/2000") rng = rng[[0, 1, 2, 3, 5, 9, 10, 11, 12]] - ser = Series(randn(len(rng)), rng) + ser = Series(np.random.randn(len(rng)), rng) _, ax = self.plt.subplots() ax = ser.plot(ax=ax) xp = DatetimeConverter.convert(datetime(1999, 1, 1), "", ax) @@ -459,8 +458,8 @@ def test_hist_layout_with_by(self): def test_hist_no_overlap(self): from matplotlib.pyplot import gcf, subplot - x = Series(randn(2)) - y = Series(randn(2)) + x = Series(np.random.randn(2)) + y = Series(np.random.randn(2)) subplot(121) x.hist() subplot(122) @@ -590,7 +589,7 @@ def test_secondary_logy(self, input_logy, expected_scale): @pytest.mark.slow def test_plot_fails_with_dupe_color_and_style(self): - x = Series(randn(2)) + x = Series(np.random.randn(2)) with pytest.raises(ValueError): _, ax = self.plt.subplots() x.plot(style="k--", color="k", ax=ax) @@ -734,7 +733,7 @@ def test_dup_datetime_index_plot(self): dr1 = date_range("1/1/2009", periods=4) dr2 = date_range("1/2/2009", periods=4) index = dr1.append(dr2) - values = randn(index.size) + values = np.random.randn(index.size) s = Series(values, index=index) _check_plot_works(s.plot) @@ -763,7 +762,7 @@ def test_errorbar_plot(self): s = Series(np.arange(10), name="x") s_err = np.random.randn(10) - d_err = DataFrame(randn(10, 2), index=s.index, columns=["x", "y"]) + d_err = DataFrame(np.random.randn(10, 2), index=s.index, columns=["x", "y"]) # test line and bar plots kinds = ["line", "bar"] for kind in kinds: @@ -785,7 +784,7 @@ def test_errorbar_plot(self): ix = date_range("1/1/2000", "1/1/2001", freq="M") ts = Series(np.arange(12), index=ix, name="x") ts_err = Series(np.random.randn(12), index=ix) - td_err = DataFrame(randn(12, 2), index=ix, columns=["x", "y"]) + td_err = DataFrame(np.random.randn(12, 2), index=ix, columns=["x", "y"]) ax = _check_plot_works(ts.plot, yerr=ts_err) self._check_has_errorbars(ax, xerr=0, yerr=1) diff --git a/pandas/tests/reshape/concat/test_series.py b/pandas/tests/reshape/concat/test_series.py index aea2840bb897f..20838a418cfea 100644 --- a/pandas/tests/reshape/concat/test_series.py +++ b/pandas/tests/reshape/concat/test_series.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest import pandas as pd @@ -66,8 +65,8 @@ def test_concat_series_axis1(self, sort=sort): tm.assert_frame_equal(result, expected) # preserve series names, #2489 - s = Series(randn(5), name="A") - s2 = Series(randn(5), name="B") + s = Series(np.random.randn(5), name="A") + s2 = Series(np.random.randn(5), name="B") result = concat([s, s2], axis=1) expected = DataFrame({"A": s, "B": s2}) @@ -78,8 +77,8 @@ def test_concat_series_axis1(self, sort=sort): tm.assert_index_equal(result.columns, Index(["A", 0], dtype="object")) # must reindex, #2603 - s = Series(randn(3), index=["c", "a", "b"], name="A") - s2 = Series(randn(4), index=["d", "a", "b", "c"], name="B") + s = Series(np.random.randn(3), index=["c", "a", "b"], name="A") + s2 = Series(np.random.randn(4), index=["d", "a", "b", "c"], name="B") result = concat([s, s2], axis=1, sort=sort) expected = DataFrame({"A": s, "B": s2}) tm.assert_frame_equal(result, expected) @@ -103,8 +102,8 @@ def test_concat_series_axis1_names_applied(self): def test_concat_series_axis1_same_names_ignore_index(self): dates = date_range("01-Jan-2013", "01-Jan-2014", freq="MS")[0:-1] - s1 = Series(randn(len(dates)), index=dates, name="value") - s2 = Series(randn(len(dates)), index=dates, name="value") + s1 = Series(np.random.randn(len(dates)), index=dates, name="value") + s2 = Series(np.random.randn(len(dates)), index=dates, name="value") result = concat([s1, s2], axis=1, ignore_index=True) expected = Index([0, 1]) diff --git a/pandas/tests/reshape/merge/test_join.py b/pandas/tests/reshape/merge/test_join.py index c1efbb8536d68..5968fd1834f8c 100644 --- a/pandas/tests/reshape/merge/test_join.py +++ b/pandas/tests/reshape/merge/test_join.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest import pandas as pd @@ -290,10 +289,10 @@ def test_join_empty_bug(self): def test_join_unconsolidated(self): # GH #331 - a = DataFrame(randn(30, 2), columns=["a", "b"]) - c = Series(randn(30)) + a = DataFrame(np.random.randn(30, 2), columns=["a", "b"]) + c = Series(np.random.randn(30)) a["c"] = c - d = DataFrame(randn(30, 1), columns=["q"]) + d = DataFrame(np.random.randn(30, 1), columns=["q"]) # it works! a.join(d) @@ -412,8 +411,8 @@ def test_join_hierarchical_mixed(self): def test_join_float64_float32(self): - a = DataFrame(randn(10, 2), columns=["a", "b"], dtype=np.float64) - b = DataFrame(randn(10, 1), columns=["c"], dtype=np.float32) + a = DataFrame(np.random.randn(10, 2), columns=["a", "b"], dtype=np.float64) + b = DataFrame(np.random.randn(10, 1), columns=["c"], dtype=np.float32) joined = a.join(b) assert joined.dtypes["a"] == "float64" assert joined.dtypes["b"] == "float64" diff --git a/pandas/tests/reshape/merge/test_multi.py b/pandas/tests/reshape/merge/test_multi.py index 68096192c51ea..65673bdde4257 100644 --- a/pandas/tests/reshape/merge/test_multi.py +++ b/pandas/tests/reshape/merge/test_multi.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest import pandas as pd @@ -406,10 +405,10 @@ def test_left_merge_na_buglet(self): left = DataFrame( { "id": list("abcde"), - "v1": randn(5), - "v2": randn(5), + "v1": np.random.randn(5), + "v2": np.random.randn(5), "dummy": list("abcde"), - "v3": randn(5), + "v3": np.random.randn(5), }, columns=["id", "v1", "v2", "dummy", "v3"], ) diff --git a/pandas/tests/test_expressions.py b/pandas/tests/test_expressions.py index 6d4c1594146de..2d862fda013d5 100644 --- a/pandas/tests/test_expressions.py +++ b/pandas/tests/test_expressions.py @@ -2,15 +2,14 @@ import re import numpy as np -from numpy.random import randn import pytest import pandas._testing as tm from pandas.core.api import DataFrame, Index, Series from pandas.core.computation import expressions as expr -_frame = DataFrame(randn(10000, 4), columns=list("ABCD"), dtype="float64") -_frame2 = DataFrame(randn(100, 4), columns=list("ABCD"), dtype="float64") +_frame = DataFrame(np.random.randn(10000, 4), columns=list("ABCD"), dtype="float64") +_frame2 = DataFrame(np.random.randn(100, 4), columns=list("ABCD"), dtype="float64") _mixed = DataFrame( { "A": _frame["A"].copy(), diff --git a/pandas/tests/test_strings.py b/pandas/tests/test_strings.py index 9be5abb9dda65..f52d0d0fccab8 100644 --- a/pandas/tests/test_strings.py +++ b/pandas/tests/test_strings.py @@ -2,7 +2,6 @@ import re import numpy as np -from numpy.random import randint import pytest from pandas._libs import lib @@ -367,7 +366,12 @@ def test_iter_single_element(self): tm.assert_series_equal(ds, s) def test_iter_object_try_string(self): - ds = Series([slice(None, randint(10), randint(10, 20)) for _ in range(4)]) + ds = Series( + [ + slice(None, np.random.randint(10), np.random.randint(10, 20)) + for _ in range(4) + ] + ) i, s = 100, "h" diff --git a/pandas/tests/window/conftest.py b/pandas/tests/window/conftest.py index e5c5579d35a5c..1780925202593 100644 --- a/pandas/tests/window/conftest.py +++ b/pandas/tests/window/conftest.py @@ -1,7 +1,6 @@ from datetime import datetime, timedelta import numpy as np -from numpy.random import randn import pytest import pandas.util._test_decorators as td @@ -254,7 +253,7 @@ def consistency_data(request): def _create_arr(): """Internal function to mock an array.""" - arr = randn(100) + arr = np.random.randn(100) locs = np.arange(20, 40) arr[locs] = np.NaN return arr @@ -276,7 +275,7 @@ def _create_series(): def _create_frame(): """Internal function to mock DataFrame.""" rng = _create_rng() - return DataFrame(randn(100, 10), index=rng, columns=np.arange(10)) + return DataFrame(np.random.randn(100, 10), index=rng, columns=np.arange(10)) @pytest.fixture diff --git a/pandas/tests/window/moments/conftest.py b/pandas/tests/window/moments/conftest.py index 39e6ae71162a9..2fab7f5c91c09 100644 --- a/pandas/tests/window/moments/conftest.py +++ b/pandas/tests/window/moments/conftest.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest from pandas import Series @@ -7,8 +6,8 @@ @pytest.fixture def binary_ew_data(): - A = Series(randn(50), index=np.arange(50)) - B = A[2:] + randn(48) + A = Series(np.random.randn(50), index=np.arange(50)) + B = A[2:] + np.random.randn(48) A[:10] = np.NaN B[-10:] = np.NaN diff --git a/pandas/tests/window/moments/test_moments_consistency_ewm.py b/pandas/tests/window/moments/test_moments_consistency_ewm.py index 089ec697b5b1c..2718bdabee96a 100644 --- a/pandas/tests/window/moments/test_moments_consistency_ewm.py +++ b/pandas/tests/window/moments/test_moments_consistency_ewm.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest from pandas import DataFrame, Series, concat @@ -63,7 +62,7 @@ def test_different_input_array_raise_exception(name, binary_ew_data): msg = "Input arrays must be of the same type!" # exception raised is Exception with pytest.raises(Exception, match=msg): - getattr(A.ewm(com=20, min_periods=5), name)(randn(50)) + getattr(A.ewm(com=20, min_periods=5), name)(np.random.randn(50)) @pytest.mark.slow diff --git a/pandas/tests/window/moments/test_moments_consistency_expanding.py b/pandas/tests/window/moments/test_moments_consistency_expanding.py index 3ec91dcb60610..eb348fda5782b 100644 --- a/pandas/tests/window/moments/test_moments_consistency_expanding.py +++ b/pandas/tests/window/moments/test_moments_consistency_expanding.py @@ -1,7 +1,6 @@ import warnings import numpy as np -from numpy.random import randn import pytest from pandas import DataFrame, Index, MultiIndex, Series, isna, notna @@ -34,7 +33,7 @@ def _check_expanding( def _check_expanding_has_min_periods(func, static_comp, has_min_periods): - ser = Series(randn(50)) + ser = Series(np.random.randn(50)) if has_min_periods: result = func(ser, min_periods=30) @@ -46,7 +45,7 @@ def _check_expanding_has_min_periods(func, static_comp, has_min_periods): assert isna(result.iloc[13]) assert notna(result.iloc[14]) - ser2 = Series(randn(20)) + ser2 = Series(np.random.randn(20)) result = func(ser2, min_periods=5) assert isna(result[3]) assert notna(result[4]) @@ -62,7 +61,7 @@ def _check_expanding_has_min_periods(func, static_comp, has_min_periods): def test_expanding_corr(series): A = series.dropna() - B = (A + randn(len(A)))[:-5] + B = (A + np.random.randn(len(A)))[:-5] result = A.expanding().corr(B) @@ -88,7 +87,7 @@ def test_expanding_quantile(series): def test_expanding_cov(series): A = series - B = (A + randn(len(A)))[:-5] + B = (A + np.random.randn(len(A)))[:-5] result = A.expanding().cov(B) diff --git a/pandas/tests/window/moments/test_moments_consistency_rolling.py b/pandas/tests/window/moments/test_moments_consistency_rolling.py index 6ab53c8e2ec0d..b7b05c1a6e30d 100644 --- a/pandas/tests/window/moments/test_moments_consistency_rolling.py +++ b/pandas/tests/window/moments/test_moments_consistency_rolling.py @@ -2,7 +2,6 @@ import warnings import numpy as np -from numpy.random import randn import pytest import pandas.util._test_decorators as td @@ -34,7 +33,7 @@ def _rolling_consistency_cases(): # binary moments def test_rolling_cov(series): A = series - B = A + randn(len(A)) + B = A + np.random.randn(len(A)) result = A.rolling(window=50, min_periods=25).cov(B) tm.assert_almost_equal(result[-1], np.cov(A[-50:], B[-50:])[0, 1]) @@ -42,7 +41,7 @@ def test_rolling_cov(series): def test_rolling_corr(series): A = series - B = A + randn(len(A)) + B = A + np.random.randn(len(A)) result = A.rolling(window=50, min_periods=25).corr(B) tm.assert_almost_equal(result[-1], np.corrcoef(A[-50:], B[-50:])[0, 1]) diff --git a/pandas/tests/window/moments/test_moments_ewm.py b/pandas/tests/window/moments/test_moments_ewm.py index 605b85344ba76..def6d7289fec2 100644 --- a/pandas/tests/window/moments/test_moments_ewm.py +++ b/pandas/tests/window/moments/test_moments_ewm.py @@ -1,5 +1,4 @@ import numpy as np -from numpy.random import randn import pytest from pandas import DataFrame, Series @@ -305,7 +304,7 @@ def test_ew_empty_series(method): @pytest.mark.parametrize("name", ["mean", "var", "vol"]) def test_ew_min_periods(min_periods, name): # excluding NaNs correctly - arr = randn(50) + arr = np.random.randn(50) arr[:10] = np.NaN arr[-10:] = np.NaN s = Series(arr)