@@ -29,20 +29,21 @@ def full_like(array, value):
2929class Numeric (Base ):
3030
3131 def test_numeric_compat (self ):
32+ pass # override Base method
3233
34+ def test_mul_int (self ):
3335 idx = self .create_index ()
34- didx = idx * idx
35-
3636 result = idx * 1
3737 tm .assert_index_equal (result , idx )
3838
39+ def test_rmul_int (self ):
40+ idx = self .create_index ()
41+
3942 result = 1 * idx
4043 tm .assert_index_equal (result , idx )
4144
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 ()
4647
4748 # truediv under PY3
4849 result = idx / 1
@@ -57,29 +58,62 @@ def test_numeric_compat(self):
5758 expected = Index (idx .values / 2 )
5859 tm .assert_index_equal (result , expected )
5960
61+ def test_floordiv_int (self ):
62+ idx = self .create_index ()
63+
6064 result = idx // 1
6165 tm .assert_index_equal (result , idx )
6266
67+ def test_mul_int_array (self ):
68+ idx = self .create_index ()
69+ didx = idx * idx
70+
6371 result = idx * np .array (5 , dtype = 'int64' )
6472 tm .assert_index_equal (result , idx * 5 )
6573
6674 arr_dtype = 'uint64' if isinstance (idx , UInt64Index ) else 'int64'
6775 result = idx * np .arange (5 , dtype = arr_dtype )
6876 tm .assert_index_equal (result , didx )
6977
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'
7083 result = idx * Series (np .arange (5 , dtype = arr_dtype ))
7184 tm .assert_series_equal (result , Series (didx ))
7285
86+ def test_mul_float_series (self ):
87+ idx = self .create_index ()
7388 rng5 = np .arange (5 , dtype = 'float64' )
89+
7490 result = idx * Series (rng5 + 0.1 )
7591 expected = Series (rng5 * (rng5 + 0.1 ))
7692 tm .assert_series_equal (result , expected )
7793
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 ()
83117
84118 result = divmod (idx , 2 )
85119 with np .errstate (all = 'ignore' ):
@@ -95,15 +129,22 @@ def test_numeric_compat(self):
95129 for r , e in zip (result , expected ):
96130 tm .assert_index_equal (r , e )
97131
132+ def test_pow_float (self ):
98133 # 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 ()
102135
103136 expected = pd .Float64Index (idx .values ** 2.0 )
104137 result = idx ** 2.0
105138 tm .assert_index_equal (result , expected )
106139
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+
107148 @pytest .mark .xfail (reason = 'GH#19252 Series has no __rdivmod__' )
108149 def test_divmod_series (self ):
109150 idx = self .create_index ()
0 commit comments