9
9
import operator
10
10
from itertools import product , starmap
11
11
12
+ from numpy import nan , inf
12
13
import numpy as np
13
14
import pandas as pd
14
15
@@ -669,7 +670,7 @@ def test_floordiv_div(self):
669
670
ser = Series ([- 1 , 0 , 1 ], name = 'first' )
670
671
671
672
result = ser // 0
672
- expected = Series ([- np . inf , np . nan , np . inf ], name = 'first' )
673
+ expected = Series ([- inf , nan , inf ], name = 'first' )
673
674
assert_series_equal (result , expected )
674
675
675
676
@@ -1068,17 +1069,17 @@ def test_timedelta64_ops_nat(self):
1068
1069
assert_series_equal (1.5 * timedelta_series ,
1069
1070
Series ([NaT , Timedelta ('1.5s' )]))
1070
1071
1071
- assert_series_equal (timedelta_series * np . nan ,
1072
+ assert_series_equal (timedelta_series * nan ,
1072
1073
nat_series_dtype_timedelta )
1073
- assert_series_equal (np . nan * timedelta_series ,
1074
+ assert_series_equal (nan * timedelta_series ,
1074
1075
nat_series_dtype_timedelta )
1075
1076
1076
1077
# division
1077
1078
assert_series_equal (timedelta_series / 2 ,
1078
1079
Series ([NaT , Timedelta ('0.5s' )]))
1079
1080
assert_series_equal (timedelta_series / 2.0 ,
1080
1081
Series ([NaT , Timedelta ('0.5s' )]))
1081
- assert_series_equal (timedelta_series / np . nan ,
1082
+ assert_series_equal (timedelta_series / nan ,
1082
1083
nat_series_dtype_timedelta )
1083
1084
1084
1085
def test_td64_sub_NaT (self ):
@@ -1853,21 +1854,10 @@ def test_operators_bitwise_int_series_with_float_series(self):
1853
1854
result = s_0123 & Series ([0.1 , 4 , - 3.14 , 2 ])
1854
1855
assert_series_equal (result , s_ftft )
1855
1856
1856
- @pytest .mark .xfail (reason = 'GH#19792 Series op doesnt support categorical' )
1857
- def test_operators_bitwise_with_int_categorical (self ):
1858
- # GH#9016: support bitwise op for integer types
1859
- # GH#??? allow for operating with Index
1860
- s_0123 = Series (range (4 ), dtype = 'int64' ).astype ('category' )
1861
- s_3333 = Series ([3 ] * 4 ).astype ('category' )
1862
-
1863
- res = s_0123 & pd .Categorical (s_3333 )
1864
- expected = Series (range (4 ), dtype = 'int64' ).astype ('category' )
1865
- assert_series_equal (res , expected )
1866
-
1867
1857
@pytest .mark .parametrize ('box' , [np .array , pd .Index , pd .Series ])
1868
1858
def test_operators_bitwise_with_int_arraylike (self , box ):
1869
1859
# GH#9016: support bitwise op for integer types
1870
- # GH#??? allow for operating with Index
1860
+ # GH#19795 allow for operating with Index
1871
1861
s_0123 = Series (range (4 ), dtype = 'int64' )
1872
1862
s_3333 = Series ([3 ] * 4 )
1873
1863
s_4444 = Series ([4 ] * 4 )
@@ -1902,19 +1892,21 @@ def test_operators_bitwise_with_integers(self):
1902
1892
s_fff = Series ([False , False , False ], index = index )
1903
1893
s_0123 = Series (range (4 ), dtype = 'int64' )
1904
1894
1905
- res = s_tft & 0
1895
+ n0 = 0
1896
+ res = s_tft & n0
1906
1897
expected = s_fff
1907
1898
assert_series_equal (res , expected )
1908
1899
1909
- res = s_0123 & 0
1900
+ res = s_0123 & n0
1910
1901
expected = Series ([0 ] * 4 )
1911
1902
assert_series_equal (res , expected )
1912
1903
1913
- res = s_tft & 1
1904
+ n1 = 1
1905
+ res = s_tft & n1
1914
1906
expected = s_tft
1915
1907
assert_series_equal (res , expected )
1916
1908
1917
- res = s_0123 & 1
1909
+ res = s_0123 & n1
1918
1910
expected = Series ([0 , 1 , 0 , 1 ])
1919
1911
assert_series_equal (res , expected )
1920
1912
@@ -1952,19 +1944,16 @@ def test_operators_bitwise_with_reindexing(self):
1952
1944
# unable to sort incompatible object via .union.
1953
1945
exp = Series ([False ] * 7 , index = ['b' , 'c' , 'a' , 0 , 1 , 2 , 3 ])
1954
1946
with tm .assert_produces_warning (RuntimeWarning ):
1955
- result = s_tft & s_0123
1956
- assert_series_equal (result , exp )
1947
+ assert_series_equal (s_tft & s_0123 , exp )
1957
1948
else :
1958
1949
exp = Series ([False ] * 7 , index = [0 , 1 , 2 , 3 , 'a' , 'b' , 'c' ])
1959
- result = s_tft & s_0123
1960
- assert_series_equal (result , exp )
1950
+ assert_series_equal (s_tft & s_0123 , exp )
1961
1951
1962
1952
# s_tft will be all false now because of reindexing like s_0123
1963
1953
if compat .PY3 :
1964
1954
# unable to sort incompatible object via .union.
1965
1955
exp = Series ([False ] * 7 , index = [0 , 1 , 2 , 3 , 'b' , 'c' , 'a' ])
1966
1956
with tm .assert_produces_warning (RuntimeWarning ):
1967
- result = s_0123 & s_tft
1968
1957
assert_series_equal (s_0123 & s_tft , exp )
1969
1958
else :
1970
1959
exp = Series ([False ] * 7 , index = [0 , 1 , 2 , 3 , 'a' , 'b' , 'c' ])
@@ -1980,9 +1969,9 @@ def test_operators_bitwise_with_nans(self):
1980
1969
1981
1970
s_ftft = Series ([False , True , False , True ])
1982
1971
s_abNd = Series (['a' , 'b' , np .NaN , 'd' ])
1983
- result = s_0123 & s_abNd
1972
+ res = s_0123 & s_abNd
1984
1973
expected = s_ftft
1985
- assert_series_equal (result , expected )
1974
+ assert_series_equal (res , expected )
1986
1975
1987
1976
def test_scalar_na_cmp_corners (self ):
1988
1977
s = Series ([2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
@@ -2193,12 +2182,12 @@ def _check_fill(meth, op, a, b, fill_value=0):
2193
2182
with np .errstate (all = 'ignore' ):
2194
2183
if amask [i ]:
2195
2184
if bmask [i ]:
2196
- exp_values .append (np . nan )
2185
+ exp_values .append (nan )
2197
2186
continue
2198
2187
exp_values .append (op (fill_value , b [i ]))
2199
2188
elif bmask [i ]:
2200
2189
if amask [i ]:
2201
- exp_values .append (np . nan )
2190
+ exp_values .append (nan )
2202
2191
continue
2203
2192
exp_values .append (op (a [i ], fill_value ))
2204
2193
else :
@@ -2208,8 +2197,8 @@ def _check_fill(meth, op, a, b, fill_value=0):
2208
2197
expected = Series (exp_values , exp_index )
2209
2198
assert_series_equal (result , expected )
2210
2199
2211
- a = Series ([np . nan , 1. , 2. , 3. , np . nan ], index = np .arange (5 ))
2212
- b = Series ([np . nan , 1 , np . nan , 3 , np . nan , 4. ], index = np .arange (6 ))
2200
+ a = Series ([nan , 1. , 2. , 3. , nan ], index = np .arange (5 ))
2201
+ b = Series ([nan , 1 , nan , 3 , nan , 4. ], index = np .arange (6 ))
2213
2202
2214
2203
pairings = []
2215
2204
for op in ['add' , 'sub' , 'mul' , 'pow' , 'truediv' , 'floordiv' ]:
0 commit comments