6
6
import warnings
7
7
8
8
import numpy as np
9
- from numpy import nan
10
- from numpy .random import randn
11
9
import pytest
12
10
13
11
from pandas .compat import PY35 , lrange
@@ -240,22 +238,22 @@ class TestDataFrameAnalytics():
240
238
241
239
@td .skip_if_no_scipy
242
240
def test_corr_pearson (self , float_frame ):
243
- float_frame ['A' ][:5 ] = nan
244
- float_frame ['B' ][5 :10 ] = nan
241
+ float_frame ['A' ][:5 ] = np . nan
242
+ float_frame ['B' ][5 :10 ] = np . nan
245
243
246
244
self ._check_method (float_frame , 'pearson' )
247
245
248
246
@td .skip_if_no_scipy
249
247
def test_corr_kendall (self , float_frame ):
250
- float_frame ['A' ][:5 ] = nan
251
- float_frame ['B' ][5 :10 ] = nan
248
+ float_frame ['A' ][:5 ] = np . nan
249
+ float_frame ['B' ][5 :10 ] = np . nan
252
250
253
251
self ._check_method (float_frame , 'kendall' )
254
252
255
253
@td .skip_if_no_scipy
256
254
def test_corr_spearman (self , float_frame ):
257
- float_frame ['A' ][:5 ] = nan
258
- float_frame ['B' ][5 :10 ] = nan
255
+ float_frame ['A' ][:5 ] = np . nan
256
+ float_frame ['B' ][5 :10 ] = np . nan
259
257
260
258
self ._check_method (float_frame , 'spearman' )
261
259
@@ -266,8 +264,8 @@ def _check_method(self, frame, method='pearson'):
266
264
267
265
@td .skip_if_no_scipy
268
266
def test_corr_non_numeric (self , float_frame , float_string_frame ):
269
- float_frame ['A' ][:5 ] = nan
270
- float_frame ['B' ][5 :10 ] = nan
267
+ float_frame ['A' ][:5 ] = np . nan
268
+ float_frame ['B' ][5 :10 ] = np . nan
271
269
272
270
# exclude non-numeric types
273
271
result = float_string_frame .corr ()
@@ -351,16 +349,16 @@ def test_cov(self, float_frame, float_string_frame):
351
349
352
350
# with NAs
353
351
frame = float_frame .copy ()
354
- frame ['A' ][:5 ] = nan
355
- frame ['B' ][5 :10 ] = nan
352
+ frame ['A' ][:5 ] = np . nan
353
+ frame ['B' ][5 :10 ] = np . nan
356
354
result = float_frame .cov (min_periods = len (float_frame ) - 8 )
357
355
expected = float_frame .cov ()
358
356
expected .loc ['A' , 'B' ] = np .nan
359
357
expected .loc ['B' , 'A' ] = np .nan
360
358
361
359
# regular
362
- float_frame ['A' ][:5 ] = nan
363
- float_frame ['B' ][:10 ] = nan
360
+ float_frame ['A' ][:5 ] = np . nan
361
+ float_frame ['B' ][:10 ] = np . nan
364
362
cov = float_frame .cov ()
365
363
366
364
tm .assert_almost_equal (cov ['A' ]['C' ],
@@ -385,7 +383,7 @@ def test_cov(self, float_frame, float_string_frame):
385
383
386
384
def test_corrwith (self , datetime_frame ):
387
385
a = datetime_frame
388
- noise = Series (randn (len (a )), index = a .index )
386
+ noise = Series (np . random . randn (len (a )), index = a .index )
389
387
390
388
b = datetime_frame .add (noise , axis = 0 )
391
389
@@ -409,8 +407,9 @@ def test_corrwith(self, datetime_frame):
409
407
# non time-series data
410
408
index = ['a' , 'b' , 'c' , 'd' , 'e' ]
411
409
columns = ['one' , 'two' , 'three' , 'four' ]
412
- df1 = DataFrame (randn (5 , 4 ), index = index , columns = columns )
413
- df2 = DataFrame (randn (4 , 4 ), index = index [:4 ], columns = columns )
410
+ df1 = DataFrame (np .random .randn (5 , 4 ), index = index , columns = columns )
411
+ df2 = DataFrame (np .random .randn (4 , 4 ),
412
+ index = index [:4 ], columns = columns )
414
413
correls = df1 .corrwith (df2 , axis = 1 )
415
414
for row in index [:4 ]:
416
415
tm .assert_almost_equal (correls [row ],
@@ -823,9 +822,9 @@ def test_min(self, float_frame_with_na, int_frame,
823
822
assert_stat_op_api ('min' , float_frame , float_string_frame )
824
823
825
824
def test_cummin (self , datetime_frame ):
826
- datetime_frame .loc [5 :10 , 0 ] = nan
827
- datetime_frame .loc [10 :15 , 1 ] = nan
828
- datetime_frame .loc [15 :, 2 ] = nan
825
+ datetime_frame .loc [5 :10 , 0 ] = np . nan
826
+ datetime_frame .loc [10 :15 , 1 ] = np . nan
827
+ datetime_frame .loc [15 :, 2 ] = np . nan
829
828
830
829
# axis = 0
831
830
cummin = datetime_frame .cummin ()
@@ -846,9 +845,9 @@ def test_cummin(self, datetime_frame):
846
845
assert np .shape (cummin_xs ) == np .shape (datetime_frame )
847
846
848
847
def test_cummax (self , datetime_frame ):
849
- datetime_frame .loc [5 :10 , 0 ] = nan
850
- datetime_frame .loc [10 :15 , 1 ] = nan
851
- datetime_frame .loc [15 :, 2 ] = nan
848
+ datetime_frame .loc [5 :10 , 0 ] = np . nan
849
+ datetime_frame .loc [10 :15 , 1 ] = np . nan
850
+ datetime_frame .loc [15 :, 2 ] = np . nan
852
851
853
852
# axis = 0
854
853
cummax = datetime_frame .cummax ()
@@ -950,9 +949,9 @@ def test_mixed_ops(self, op):
950
949
assert len (result ) == 2
951
950
952
951
def test_cumsum (self , datetime_frame ):
953
- datetime_frame .loc [5 :10 , 0 ] = nan
954
- datetime_frame .loc [10 :15 , 1 ] = nan
955
- datetime_frame .loc [15 :, 2 ] = nan
952
+ datetime_frame .loc [5 :10 , 0 ] = np . nan
953
+ datetime_frame .loc [10 :15 , 1 ] = np . nan
954
+ datetime_frame .loc [15 :, 2 ] = np . nan
956
955
957
956
# axis = 0
958
957
cumsum = datetime_frame .cumsum ()
@@ -973,9 +972,9 @@ def test_cumsum(self, datetime_frame):
973
972
assert np .shape (cumsum_xs ) == np .shape (datetime_frame )
974
973
975
974
def test_cumprod (self , datetime_frame ):
976
- datetime_frame .loc [5 :10 , 0 ] = nan
977
- datetime_frame .loc [10 :15 , 1 ] = nan
978
- datetime_frame .loc [15 :, 2 ] = nan
975
+ datetime_frame .loc [5 :10 , 0 ] = np . nan
976
+ datetime_frame .loc [10 :15 , 1 ] = np . nan
977
+ datetime_frame .loc [15 :, 2 ] = np . nan
979
978
980
979
# axis = 0
981
980
cumprod = datetime_frame .cumprod ()
@@ -1753,7 +1752,7 @@ def test_round(self):
1753
1752
expected_neg_rounded )
1754
1753
1755
1754
# nan in Series round
1756
- nan_round_Series = Series ({'col1' : nan , 'col2' : 1 })
1755
+ nan_round_Series = Series ({'col1' : np . nan , 'col2' : 1 })
1757
1756
1758
1757
# TODO(wesm): unused?
1759
1758
expected_nan_round = DataFrame ({ # noqa
@@ -2084,8 +2083,10 @@ def test_dot(self):
2084
2083
result = A .dot (b )
2085
2084
2086
2085
# unaligned
2087
- df = DataFrame (randn (3 , 4 ), index = [1 , 2 , 3 ], columns = lrange (4 ))
2088
- df2 = DataFrame (randn (5 , 3 ), index = lrange (5 ), columns = [1 , 2 , 3 ])
2086
+ df = DataFrame (np .random .randn (3 , 4 ),
2087
+ index = [1 , 2 , 3 ], columns = lrange (4 ))
2088
+ df2 = DataFrame (np .random .randn (5 , 3 ),
2089
+ index = lrange (5 ), columns = [1 , 2 , 3 ])
2089
2090
2090
2091
with pytest .raises (ValueError , match = 'aligned' ):
2091
2092
df .dot (df2 )
@@ -2144,8 +2145,10 @@ def test_matmul(self):
2144
2145
tm .assert_frame_equal (result , expected )
2145
2146
2146
2147
# unaligned
2147
- df = DataFrame (randn (3 , 4 ), index = [1 , 2 , 3 ], columns = lrange (4 ))
2148
- df2 = DataFrame (randn (5 , 3 ), index = lrange (5 ), columns = [1 , 2 , 3 ])
2148
+ df = DataFrame (np .random .randn (3 , 4 ),
2149
+ index = [1 , 2 , 3 ], columns = lrange (4 ))
2150
+ df2 = DataFrame (np .random .randn (5 , 3 ),
2151
+ index = lrange (5 ), columns = [1 , 2 , 3 ])
2149
2152
2150
2153
with pytest .raises (ValueError , match = 'aligned' ):
2151
2154
operator .matmul (df , df2 )
0 commit comments