6
6
import warnings
7
7
8
8
import numpy as np
9
- from numpy .random import rand , randint , randn
10
9
import pytest
11
10
12
11
from pandas .compat import is_platform_windows
@@ -126,15 +125,15 @@ def _is_py3_complex_incompat(result, expected):
126
125
@pytest .fixture (params = list (range (5 )))
127
126
def lhs (request ):
128
127
129
- nan_df1 = DataFrame (rand (10 , 5 ))
128
+ nan_df1 = DataFrame (np . random . rand (10 , 5 ))
130
129
nan_df1 [nan_df1 > 0.5 ] = np .nan
131
130
132
131
opts = (
133
- DataFrame (randn (10 , 5 )),
134
- Series (randn (5 )),
132
+ DataFrame (np . random . randn (10 , 5 )),
133
+ Series (np . random . randn (5 )),
135
134
Series ([1 , 2 , np .nan , np .nan , 5 ]),
136
135
nan_df1 ,
137
- randn (),
136
+ np . random . randn (),
138
137
)
139
138
return opts [request .param ]
140
139
@@ -455,7 +454,7 @@ def test_frame_invert(self):
455
454
# ~ ##
456
455
# frame
457
456
# float always raises
458
- lhs = DataFrame (randn (5 , 2 ))
457
+ lhs = DataFrame (np . random . randn (5 , 2 ))
459
458
if self .engine == "numexpr" :
460
459
msg = "couldn't find matching opcode for 'invert_dd'"
461
460
with pytest .raises (NotImplementedError , match = msg ):
@@ -466,7 +465,7 @@ def test_frame_invert(self):
466
465
result = pd .eval (expr , engine = self .engine , parser = self .parser )
467
466
468
467
# int raises on numexpr
469
- lhs = DataFrame (randint (5 , size = (5 , 2 )))
468
+ lhs = DataFrame (np . random . randint (5 , size = (5 , 2 )))
470
469
if self .engine == "numexpr" :
471
470
msg = "couldn't find matching opcode for 'invert"
472
471
with pytest .raises (NotImplementedError , match = msg ):
@@ -477,13 +476,13 @@ def test_frame_invert(self):
477
476
tm .assert_frame_equal (expect , result )
478
477
479
478
# bool always works
480
- lhs = DataFrame (rand (5 , 2 ) > 0.5 )
479
+ lhs = DataFrame (np . random . rand (5 , 2 ) > 0.5 )
481
480
expect = ~ lhs
482
481
result = pd .eval (expr , engine = self .engine , parser = self .parser )
483
482
tm .assert_frame_equal (expect , result )
484
483
485
484
# object raises
486
- lhs = DataFrame ({"b" : ["a" , 1 , 2.0 ], "c" : rand (3 ) > 0.5 })
485
+ lhs = DataFrame ({"b" : ["a" , 1 , 2.0 ], "c" : np . random . rand (3 ) > 0.5 })
487
486
if self .engine == "numexpr" :
488
487
with pytest .raises (ValueError , match = "unknown type object" ):
489
488
result = pd .eval (expr , engine = self .engine , parser = self .parser )
@@ -498,7 +497,7 @@ def test_series_invert(self):
498
497
499
498
# series
500
499
# float raises
501
- lhs = Series (randn (5 ))
500
+ lhs = Series (np . random . randn (5 ))
502
501
if self .engine == "numexpr" :
503
502
msg = "couldn't find matching opcode for 'invert_dd'"
504
503
with pytest .raises (NotImplementedError , match = msg ):
@@ -509,7 +508,7 @@ def test_series_invert(self):
509
508
result = pd .eval (expr , engine = self .engine , parser = self .parser )
510
509
511
510
# int raises on numexpr
512
- lhs = Series (randint (5 , size = 5 ))
511
+ lhs = Series (np . random . randint (5 , size = 5 ))
513
512
if self .engine == "numexpr" :
514
513
msg = "couldn't find matching opcode for 'invert"
515
514
with pytest .raises (NotImplementedError , match = msg ):
@@ -520,7 +519,7 @@ def test_series_invert(self):
520
519
tm .assert_series_equal (expect , result )
521
520
522
521
# bool
523
- lhs = Series (rand (5 ) > 0.5 )
522
+ lhs = Series (np . random . rand (5 ) > 0.5 )
524
523
expect = ~ lhs
525
524
result = pd .eval (expr , engine = self .engine , parser = self .parser )
526
525
tm .assert_series_equal (expect , result )
@@ -543,19 +542,19 @@ def test_frame_negate(self):
543
542
expr = self .ex ("-" )
544
543
545
544
# float
546
- lhs = DataFrame (randn (5 , 2 ))
545
+ lhs = DataFrame (np . random . randn (5 , 2 ))
547
546
expect = - lhs
548
547
result = pd .eval (expr , engine = self .engine , parser = self .parser )
549
548
tm .assert_frame_equal (expect , result )
550
549
551
550
# int
552
- lhs = DataFrame (randint (5 , size = (5 , 2 )))
551
+ lhs = DataFrame (np . random . randint (5 , size = (5 , 2 )))
553
552
expect = - lhs
554
553
result = pd .eval (expr , engine = self .engine , parser = self .parser )
555
554
tm .assert_frame_equal (expect , result )
556
555
557
556
# bool doesn't work with numexpr but works elsewhere
558
- lhs = DataFrame (rand (5 , 2 ) > 0.5 )
557
+ lhs = DataFrame (np . random . rand (5 , 2 ) > 0.5 )
559
558
if self .engine == "numexpr" :
560
559
msg = "couldn't find matching opcode for 'neg_bb'"
561
560
with pytest .raises (NotImplementedError , match = msg ):
@@ -569,19 +568,19 @@ def test_series_negate(self):
569
568
expr = self .ex ("-" )
570
569
571
570
# float
572
- lhs = Series (randn (5 ))
571
+ lhs = Series (np . random . randn (5 ))
573
572
expect = - lhs
574
573
result = pd .eval (expr , engine = self .engine , parser = self .parser )
575
574
tm .assert_series_equal (expect , result )
576
575
577
576
# int
578
- lhs = Series (randint (5 , size = 5 ))
577
+ lhs = Series (np . random . randint (5 , size = 5 ))
579
578
expect = - lhs
580
579
result = pd .eval (expr , engine = self .engine , parser = self .parser )
581
580
tm .assert_series_equal (expect , result )
582
581
583
582
# bool doesn't work with numexpr but works elsewhere
584
- lhs = Series (rand (5 ) > 0.5 )
583
+ lhs = Series (np . random . rand (5 ) > 0.5 )
585
584
if self .engine == "numexpr" :
586
585
msg = "couldn't find matching opcode for 'neg_bb'"
587
586
with pytest .raises (NotImplementedError , match = msg ):
@@ -595,11 +594,11 @@ def test_series_negate(self):
595
594
"lhs" ,
596
595
[
597
596
# Float
598
- DataFrame (randn (5 , 2 )),
597
+ DataFrame (np . random . randn (5 , 2 )),
599
598
# Int
600
- DataFrame (randint (5 , size = (5 , 2 ))),
599
+ DataFrame (np . random . randint (5 , size = (5 , 2 ))),
601
600
# bool doesn't work with numexpr but works elsewhere
602
- DataFrame (rand (5 , 2 ) > 0.5 ),
601
+ DataFrame (np . random . rand (5 , 2 ) > 0.5 ),
603
602
],
604
603
)
605
604
def test_frame_pos (self , lhs ):
@@ -613,11 +612,11 @@ def test_frame_pos(self, lhs):
613
612
"lhs" ,
614
613
[
615
614
# Float
616
- Series (randn (5 )),
615
+ Series (np . random . randn (5 )),
617
616
# Int
618
- Series (randint (5 , size = 5 )),
617
+ Series (np . random . randint (5 , size = 5 )),
619
618
# bool doesn't work with numexpr but works elsewhere
620
- Series (rand (5 ) > 0.5 ),
619
+ Series (np . random . rand (5 ) > 0.5 ),
621
620
],
622
621
)
623
622
def test_series_pos (self , lhs ):
@@ -688,7 +687,7 @@ def test_disallow_scalar_bool_ops(self):
688
687
exprs += ("2 * x > 2 or 1 and 2" ,)
689
688
exprs += ("2 * df > 3 and 1 or a" ,)
690
689
691
- x , a , b , df = np .random .randn (3 ), 1 , 2 , DataFrame (randn (3 , 2 )) # noqa
690
+ x , a , b , df = np .random .randn (3 ), 1 , 2 , DataFrame (np . random . randn (3 , 2 )) # noqa
692
691
for ex in exprs :
693
692
msg = "cannot evaluate scalar only bool ops|'BoolOp' nodes are not"
694
693
with pytest .raises (NotImplementedError , match = msg ):
@@ -909,7 +908,7 @@ def test_frame_comparison(self, engine, parser, r_idx_type, c_idx_type):
909
908
res = pd .eval ("df < 2" , engine = engine , parser = parser )
910
909
tm .assert_frame_equal (res , df < 2 )
911
910
912
- df3 = DataFrame (randn (* df .shape ), index = df .index , columns = df .columns )
911
+ df3 = DataFrame (np . random . randn (* df .shape ), index = df .index , columns = df .columns )
913
912
res = pd .eval ("df < df3" , engine = engine , parser = parser )
914
913
tm .assert_frame_equal (res , df < df3 )
915
914
@@ -1089,8 +1088,8 @@ def test_complex_series_frame_alignment(self, engine, parser, r1, c1, r2, c2):
1089
1088
tm .assert_frame_equal (res , expected )
1090
1089
1091
1090
def test_performance_warning_for_poor_alignment (self , engine , parser ):
1092
- df = DataFrame (randn (1000 , 10 ))
1093
- s = Series (randn (10000 ))
1091
+ df = DataFrame (np . random . randn (1000 , 10 ))
1092
+ s = Series (np . random . randn (10000 ))
1094
1093
if engine == "numexpr" :
1095
1094
seen = PerformanceWarning
1096
1095
else :
@@ -1099,17 +1098,17 @@ def test_performance_warning_for_poor_alignment(self, engine, parser):
1099
1098
with tm .assert_produces_warning (seen ):
1100
1099
pd .eval ("df + s" , engine = engine , parser = parser )
1101
1100
1102
- s = Series (randn (1000 ))
1101
+ s = Series (np . random . randn (1000 ))
1103
1102
with tm .assert_produces_warning (False ):
1104
1103
pd .eval ("df + s" , engine = engine , parser = parser )
1105
1104
1106
- df = DataFrame (randn (10 , 10000 ))
1107
- s = Series (randn (10000 ))
1105
+ df = DataFrame (np . random . randn (10 , 10000 ))
1106
+ s = Series (np . random . randn (10000 ))
1108
1107
with tm .assert_produces_warning (False ):
1109
1108
pd .eval ("df + s" , engine = engine , parser = parser )
1110
1109
1111
- df = DataFrame (randn (10 , 10 ))
1112
- s = Series (randn (10000 ))
1110
+ df = DataFrame (np . random . randn (10 , 10 ))
1111
+ s = Series (np . random . randn (10000 ))
1113
1112
1114
1113
is_python_engine = engine == "python"
1115
1114
@@ -1206,8 +1205,8 @@ def test_bool_ops_with_constants(self, rhs, lhs, op):
1206
1205
assert res == exp
1207
1206
1208
1207
def test_4d_ndarray_fails (self ):
1209
- x = randn (3 , 4 , 5 , 6 )
1210
- y = Series (randn (10 ))
1208
+ x = np . random . randn (3 , 4 , 5 , 6 )
1209
+ y = Series (np . random . randn (10 ))
1211
1210
msg = "N-dimensional objects, where N > 2, are not supported with eval"
1212
1211
with pytest .raises (NotImplementedError , match = msg ):
1213
1212
self .eval ("x + y" , local_dict = {"x" : x , "y" : y })
@@ -1217,7 +1216,7 @@ def test_constant(self):
1217
1216
assert x == 1
1218
1217
1219
1218
def test_single_variable (self ):
1220
- df = DataFrame (randn (10 , 2 ))
1219
+ df = DataFrame (np . random . randn (10 , 2 ))
1221
1220
df2 = self .eval ("df" , local_dict = {"df" : df })
1222
1221
tm .assert_frame_equal (df , df2 )
1223
1222
@@ -1574,7 +1573,7 @@ def test_nested_period_index_subscript_expression(self):
1574
1573
tm .assert_frame_equal (r , e )
1575
1574
1576
1575
def test_date_boolean (self ):
1577
- df = DataFrame (randn (5 , 3 ))
1576
+ df = DataFrame (np . random . randn (5 , 3 ))
1578
1577
df ["dates1" ] = date_range ("1/1/2012" , periods = 5 )
1579
1578
res = self .eval (
1580
1579
"df.dates1 < 20130101" ,
@@ -1859,7 +1858,7 @@ class TestMathNumExprPython(TestMathPythonPython):
1859
1858
parser = "python"
1860
1859
1861
1860
1862
- _var_s = randn (10 )
1861
+ _var_s = np . random . randn (10 )
1863
1862
1864
1863
1865
1864
class TestScope :
0 commit comments