2
2
import string
3
3
4
4
import numpy as np
5
- from numpy import random
5
+ from numpy . random import choice , normal , rand , randint , randn , random
6
6
import pytest
7
7
8
8
import pandas .util ._test_decorators as td
@@ -21,7 +21,7 @@ class TestDataFramePlots(TestPlotBase):
21
21
@pytest .mark .slow
22
22
def test_boxplot_legacy1 (self ):
23
23
df = DataFrame (
24
- np . random . randn (6 , 4 ),
24
+ randn (6 , 4 ),
25
25
index = list (string .ascii_letters [:6 ]),
26
26
columns = ["one" , "two" , "three" , "four" ],
27
27
)
@@ -45,7 +45,7 @@ def test_boxplot_legacy1(self):
45
45
46
46
@pytest .mark .slow
47
47
def test_boxplot_legacy2 (self ):
48
- df = DataFrame (np . random . rand (10 , 2 ), columns = ["Col1" , "Col2" ])
48
+ df = DataFrame (rand (10 , 2 ), columns = ["Col1" , "Col2" ])
49
49
df ["X" ] = Series (["A" , "A" , "A" , "A" , "A" , "B" , "B" , "B" , "B" , "B" ])
50
50
df ["Y" ] = Series (["A" ] * 10 )
51
51
with tm .assert_produces_warning (UserWarning ):
@@ -90,7 +90,7 @@ def test_boxplot_return_type_legacy(self):
90
90
import matplotlib as mpl # noqa
91
91
92
92
df = DataFrame (
93
- np . random . randn (6 , 4 ),
93
+ randn (6 , 4 ),
94
94
index = list (string .ascii_letters [:6 ]),
95
95
columns = ["one" , "two" , "three" , "four" ],
96
96
)
@@ -120,7 +120,7 @@ def _check_ax_limits(col, ax):
120
120
assert y_max >= col .max ()
121
121
122
122
df = self .hist_df .copy ()
123
- df ["age" ] = np . random . randint (1 , 20 , df .shape [0 ])
123
+ df ["age" ] = randint (1 , 20 , df .shape [0 ])
124
124
# One full row
125
125
height_ax , weight_ax = df .boxplot (["height" , "weight" ], by = "category" )
126
126
_check_ax_limits (df ["height" ], height_ax )
@@ -141,13 +141,13 @@ def _check_ax_limits(col, ax):
141
141
142
142
@pytest .mark .slow
143
143
def test_boxplot_empty_column (self ):
144
- df = DataFrame (np . random . randn (20 , 4 ))
144
+ df = DataFrame (randn (20 , 4 ))
145
145
df .loc [:, 0 ] = np .nan
146
146
_check_plot_works (df .boxplot , return_type = "axes" )
147
147
148
148
@pytest .mark .slow
149
149
def test_figsize (self ):
150
- df = DataFrame (np . random . rand (10 , 5 ), columns = ["A" , "B" , "C" , "D" , "E" ])
150
+ df = DataFrame (rand (10 , 5 ), columns = ["A" , "B" , "C" , "D" , "E" ])
151
151
result = df .boxplot (return_type = "axes" , figsize = (12 , 8 ))
152
152
assert result .figure .bbox_inches .width == 12
153
153
assert result .figure .bbox_inches .height == 8
@@ -163,8 +163,8 @@ def test_boxplot_numeric_data(self):
163
163
df = DataFrame (
164
164
{
165
165
"a" : date_range ("2012-01-01" , periods = 100 ),
166
- "b" : np . random . randn (100 ),
167
- "c" : np . random . randn (100 ) + 2 ,
166
+ "b" : randn (100 ),
167
+ "c" : randn (100 ) + 2 ,
168
168
"d" : date_range ("2012-01-01" , periods = 100 ).astype (str ),
169
169
"e" : date_range ("2012-01-01" , periods = 100 , tz = "UTC" ),
170
170
"f" : timedelta_range ("1 days" , periods = 100 ),
@@ -186,7 +186,7 @@ def test_boxplot_numeric_data(self):
186
186
)
187
187
def test_color_kwd (self , colors_kwd , expected ):
188
188
# GH: 26214
189
- df = DataFrame (random . rand (10 , 2 ))
189
+ df = DataFrame (rand (10 , 2 ))
190
190
result = df .boxplot (color = colors_kwd , return_type = "dict" )
191
191
for k , v in expected .items ():
192
192
assert result [k ][0 ].get_color () == v
@@ -197,7 +197,7 @@ def test_color_kwd(self, colors_kwd, expected):
197
197
)
198
198
def test_color_kwd_errors (self , dict_colors , msg ):
199
199
# GH: 26214
200
- df = DataFrame (random . rand (10 , 2 ))
200
+ df = DataFrame (rand (10 , 2 ))
201
201
with pytest .raises (ValueError , match = msg ):
202
202
df .boxplot (color = dict_colors , return_type = "dict" )
203
203
@@ -212,7 +212,7 @@ def test_color_kwd_errors(self, dict_colors, msg):
212
212
)
213
213
def test_specified_props_kwd (self , props , expected ):
214
214
# GH 30346
215
- df = DataFrame ({k : np . random . random (100 ) for k in "ABC" })
215
+ df = DataFrame ({k : random (100 ) for k in "ABC" })
216
216
kwd = {props : dict (color = "C1" )}
217
217
result = df .boxplot (return_type = "dict" , ** kwd )
218
218
@@ -233,7 +233,7 @@ def test_boxplot_legacy1(self):
233
233
@pytest .mark .slow
234
234
def test_boxplot_legacy2 (self ):
235
235
tuples = zip (string .ascii_letters [:10 ], range (10 ))
236
- df = DataFrame (np . random . rand (10 , 3 ), index = MultiIndex .from_tuples (tuples ))
236
+ df = DataFrame (rand (10 , 3 ), index = MultiIndex .from_tuples (tuples ))
237
237
grouped = df .groupby (level = 1 )
238
238
with tm .assert_produces_warning (UserWarning ):
239
239
axes = _check_plot_works (grouped .boxplot , return_type = "axes" )
@@ -245,7 +245,7 @@ def test_boxplot_legacy2(self):
245
245
@pytest .mark .slow
246
246
def test_boxplot_legacy3 (self ):
247
247
tuples = zip (string .ascii_letters [:10 ], range (10 ))
248
- df = DataFrame (np . random . rand (10 , 3 ), index = MultiIndex .from_tuples (tuples ))
248
+ df = DataFrame (rand (10 , 3 ), index = MultiIndex .from_tuples (tuples ))
249
249
grouped = df .unstack (level = 1 ).groupby (level = 0 , axis = 1 )
250
250
with tm .assert_produces_warning (UserWarning ):
251
251
axes = _check_plot_works (grouped .boxplot , return_type = "axes" )
@@ -256,10 +256,10 @@ def test_boxplot_legacy3(self):
256
256
@pytest .mark .slow
257
257
def test_grouped_plot_fignums (self ):
258
258
n = 10
259
- weight = Series (np . random . normal (166 , 20 , size = n ))
260
- height = Series (np . random . normal (60 , 10 , size = n ))
259
+ weight = Series (normal (166 , 20 , size = n ))
260
+ height = Series (normal (60 , 10 , size = n ))
261
261
with tm .RNGContext (42 ):
262
- gender = np . random . choice (["male" , "female" ], size = n )
262
+ gender = choice (["male" , "female" ], size = n )
263
263
df = DataFrame ({"height" : height , "weight" : weight , "gender" : gender })
264
264
gb = df .groupby ("gender" )
265
265
@@ -293,7 +293,7 @@ def test_grouped_box_return_type(self):
293
293
self ._check_box_return_type (result , "dict" , expected_keys = ["Male" , "Female" ])
294
294
295
295
columns2 = "X B C D A G Y N Q O" .split ()
296
- df2 = DataFrame (random . randn (50 , 10 ), columns = columns2 )
296
+ df2 = DataFrame (randn (50 , 10 ), columns = columns2 )
297
297
categories2 = "A B C D E F G H I J" .split ()
298
298
df2 ["category" ] = categories2 * 5
299
299
0 commit comments