@@ -29,20 +29,21 @@ def full_like(array, value):
29
29
class Numeric (Base ):
30
30
31
31
def test_numeric_compat (self ):
32
+ pass # override Base method
32
33
34
+ def test_mul_int (self ):
33
35
idx = self .create_index ()
34
- didx = idx * idx
35
-
36
36
result = idx * 1
37
37
tm .assert_index_equal (result , idx )
38
38
39
+ def test_rmul_int (self ):
40
+ idx = self .create_index ()
41
+
39
42
result = 1 * idx
40
43
tm .assert_index_equal (result , idx )
41
44
42
- # in general not true for RangeIndex
43
- if not isinstance (idx , RangeIndex ):
44
- result = idx * idx
45
- tm .assert_index_equal (result , idx ** 2 )
45
+ def test_div_int (self ):
46
+ idx = self .create_index ()
46
47
47
48
# truediv under PY3
48
49
result = idx / 1
@@ -57,29 +58,62 @@ def test_numeric_compat(self):
57
58
expected = Index (idx .values / 2 )
58
59
tm .assert_index_equal (result , expected )
59
60
61
+ def test_floordiv_int (self ):
62
+ idx = self .create_index ()
63
+
60
64
result = idx // 1
61
65
tm .assert_index_equal (result , idx )
62
66
67
+ def test_mul_int_array (self ):
68
+ idx = self .create_index ()
69
+ didx = idx * idx
70
+
63
71
result = idx * np .array (5 , dtype = 'int64' )
64
72
tm .assert_index_equal (result , idx * 5 )
65
73
66
74
arr_dtype = 'uint64' if isinstance (idx , UInt64Index ) else 'int64'
67
75
result = idx * np .arange (5 , dtype = arr_dtype )
68
76
tm .assert_index_equal (result , didx )
69
77
78
+ def test_mul_int_series (self ):
79
+ idx = self .create_index ()
80
+ didx = idx * idx
81
+
82
+ arr_dtype = 'uint64' if isinstance (idx , UInt64Index ) else 'int64'
70
83
result = idx * Series (np .arange (5 , dtype = arr_dtype ))
71
84
tm .assert_series_equal (result , Series (didx ))
72
85
86
+ def test_mul_float_series (self ):
87
+ idx = self .create_index ()
73
88
rng5 = np .arange (5 , dtype = 'float64' )
89
+
74
90
result = idx * Series (rng5 + 0.1 )
75
91
expected = Series (rng5 * (rng5 + 0.1 ))
76
92
tm .assert_series_equal (result , expected )
77
93
78
- # invalid
79
- pytest .raises (TypeError ,
80
- lambda : idx * date_range ('20130101' , periods = 5 ))
81
- pytest .raises (ValueError , lambda : idx * idx [0 :3 ])
82
- pytest .raises (ValueError , lambda : idx * np .array ([1 , 2 ]))
94
+ def test_mul_index (self ):
95
+ idx = self .create_index ()
96
+
97
+ # in general not true for RangeIndex
98
+ if not isinstance (idx , RangeIndex ):
99
+ result = idx * idx
100
+ tm .assert_index_equal (result , idx ** 2 )
101
+
102
+ def test_mul_datelike_raises (self ):
103
+ idx = self .create_index ()
104
+ with pytest .raises (TypeError ):
105
+ idx * date_range ('20130101' , periods = 5 )
106
+
107
+ def test_mul_size_mismatch_raises (self ):
108
+ idx = self .create_index ()
109
+
110
+ with pytest .raises (ValueError ):
111
+ idx * idx [0 :3 ]
112
+ with pytest .raises (ValueError ):
113
+ idx * np .array ([1 , 2 ])
114
+
115
+ def test_divmod (self ):
116
+ idx = self .create_index ()
83
117
84
118
result = divmod (idx , 2 )
85
119
with np .errstate (all = 'ignore' ):
@@ -95,15 +129,22 @@ def test_numeric_compat(self):
95
129
for r , e in zip (result , expected ):
96
130
tm .assert_index_equal (r , e )
97
131
132
+ def test_pow_float (self ):
98
133
# test power calculations both ways, GH 14973
99
- expected = pd .Float64Index (2.0 ** idx .values )
100
- result = 2.0 ** idx
101
- tm .assert_index_equal (result , expected )
134
+ idx = self .create_index ()
102
135
103
136
expected = pd .Float64Index (idx .values ** 2.0 )
104
137
result = idx ** 2.0
105
138
tm .assert_index_equal (result , expected )
106
139
140
+ def test_rpow_float (self ):
141
+ # test power calculations both ways, GH 14973
142
+ idx = self .create_index ()
143
+
144
+ expected = pd .Float64Index (2.0 ** idx .values )
145
+ result = 2.0 ** idx
146
+ tm .assert_index_equal (result , expected )
147
+
107
148
@pytest .mark .xfail (reason = 'GH#19252 Series has no __rdivmod__' )
108
149
def test_divmod_series (self ):
109
150
idx = self .create_index ()
0 commit comments