@@ -779,7 +779,8 @@ def test_different_nans(self):
779
779
expected = np .array ([np .nan ])
780
780
tm .assert_numpy_array_equal (result , expected )
781
781
782
- def test_first_nan_kept (self ):
782
+ @pytest .mark .parametrize ("el_type" , [np .float64 , object ])
783
+ def test_first_nan_kept (self , el_type ):
783
784
# GH 22295
784
785
# create different nans from bit-patterns:
785
786
bits_for_nan1 = 0xFFF8000000000001
@@ -788,13 +789,12 @@ def test_first_nan_kept(self):
788
789
NAN2 = struct .unpack ("d" , struct .pack ("=Q" , bits_for_nan2 ))[0 ]
789
790
assert NAN1 != NAN1
790
791
assert NAN2 != NAN2
791
- for el_type in [np .float64 , object ]:
792
- a = np .array ([NAN1 , NAN2 ], dtype = el_type )
793
- result = pd .unique (a )
794
- assert result .size == 1
795
- # use bit patterns to identify which nan was kept:
796
- result_nan_bits = struct .unpack ("=Q" , struct .pack ("d" , result [0 ]))[0 ]
797
- assert result_nan_bits == bits_for_nan1
792
+ a = np .array ([NAN1 , NAN2 ], dtype = el_type )
793
+ result = pd .unique (a )
794
+ assert result .size == 1
795
+ # use bit patterns to identify which nan was kept:
796
+ result_nan_bits = struct .unpack ("=Q" , struct .pack ("d" , result [0 ]))[0 ]
797
+ assert result_nan_bits == bits_for_nan1
798
798
799
799
def test_do_not_mangle_na_values (self , unique_nulls_fixture , unique_nulls_fixture2 ):
800
800
# GH 22295
@@ -1261,21 +1261,20 @@ def test_dropna(self):
1261
1261
expected = Series ([3 , 2 , 1 ], index = [5.0 , 10.3 , np .nan ])
1262
1262
tm .assert_series_equal (result , expected )
1263
1263
1264
- def test_value_counts_normalized (self ):
1264
+ @pytest .mark .parametrize ("dtype" , (np .float64 , object , "M8[ns]" ))
1265
+ def test_value_counts_normalized (self , dtype ):
1265
1266
# GH12558
1266
1267
s = Series ([1 ] * 2 + [2 ] * 3 + [np .nan ] * 5 )
1267
- dtypes = (np .float64 , object , "M8[ns]" )
1268
- for t in dtypes :
1269
- s_typed = s .astype (t )
1270
- result = s_typed .value_counts (normalize = True , dropna = False )
1271
- expected = Series (
1272
- [0.5 , 0.3 , 0.2 ], index = Series ([np .nan , 2.0 , 1.0 ], dtype = t )
1273
- )
1274
- tm .assert_series_equal (result , expected )
1268
+ s_typed = s .astype (dtype )
1269
+ result = s_typed .value_counts (normalize = True , dropna = False )
1270
+ expected = Series (
1271
+ [0.5 , 0.3 , 0.2 ], index = Series ([np .nan , 2.0 , 1.0 ], dtype = dtype )
1272
+ )
1273
+ tm .assert_series_equal (result , expected )
1275
1274
1276
- result = s_typed .value_counts (normalize = True , dropna = True )
1277
- expected = Series ([0.6 , 0.4 ], index = Series ([2.0 , 1.0 ], dtype = t ))
1278
- tm .assert_series_equal (result , expected )
1275
+ result = s_typed .value_counts (normalize = True , dropna = True )
1276
+ expected = Series ([0.6 , 0.4 ], index = Series ([2.0 , 1.0 ], dtype = dtype ))
1277
+ tm .assert_series_equal (result , expected )
1279
1278
1280
1279
def test_value_counts_uint64 (self ):
1281
1280
arr = np .array ([2 ** 63 ], dtype = np .uint64 )
@@ -1479,13 +1478,10 @@ def test_datetime_likes(self):
1479
1478
res_false = s .duplicated (keep = False )
1480
1479
tm .assert_series_equal (res_false , Series (exp_false ))
1481
1480
1482
- def test_unique_index (self ):
1483
- cases = [Index ([1 , 2 , 3 ]), pd .RangeIndex (0 , 3 )]
1484
- for case in cases :
1485
- assert case .is_unique is True
1486
- tm .assert_numpy_array_equal (
1487
- case .duplicated (), np .array ([False , False , False ])
1488
- )
1481
+ @pytest .mark .parametrize ("case" , [Index ([1 , 2 , 3 ]), pd .RangeIndex (0 , 3 )])
1482
+ def test_unique_index (self , case ):
1483
+ assert case .is_unique is True
1484
+ tm .assert_numpy_array_equal (case .duplicated (), np .array ([False , False , False ]))
1489
1485
1490
1486
@pytest .mark .parametrize (
1491
1487
"arr, uniques" ,
@@ -1744,20 +1740,25 @@ def test_unique_label_indices():
1744
1740
1745
1741
class TestRank :
1746
1742
@td .skip_if_no_scipy
1747
- def test_scipy_compat (self ):
1743
+ @pytest .mark .parametrize (
1744
+ "arr" ,
1745
+ [
1746
+ [np .nan , np .nan , 5.0 , 5.0 , 5.0 , np .nan , 1 , 2 , 3 , np .nan ],
1747
+ [4.0 , np .nan , 5.0 , 5.0 , 5.0 , np .nan , 1 , 2 , 4.0 , np .nan ],
1748
+ ],
1749
+ )
1750
+ def test_scipy_compat (self , arr ):
1748
1751
from scipy .stats import rankdata
1749
1752
1750
- def _check (arr ):
1751
- mask = ~ np .isfinite (arr )
1752
- arr = arr .copy ()
1753
- result = libalgos .rank_1d (arr )
1754
- arr [mask ] = np .inf
1755
- exp = rankdata (arr )
1756
- exp [mask ] = np .nan
1757
- tm .assert_almost_equal (result , exp )
1753
+ arr = np .array (arr )
1758
1754
1759
- _check (np .array ([np .nan , np .nan , 5.0 , 5.0 , 5.0 , np .nan , 1 , 2 , 3 , np .nan ]))
1760
- _check (np .array ([4.0 , np .nan , 5.0 , 5.0 , 5.0 , np .nan , 1 , 2 , 4.0 , np .nan ]))
1755
+ mask = ~ np .isfinite (arr )
1756
+ arr = arr .copy ()
1757
+ result = libalgos .rank_1d (arr )
1758
+ arr [mask ] = np .inf
1759
+ exp = rankdata (arr )
1760
+ exp [mask ] = np .nan
1761
+ tm .assert_almost_equal (result , exp )
1761
1762
1762
1763
@pytest .mark .parametrize ("dtype" , np .typecodes ["AllInteger" ])
1763
1764
def test_basic (self , writable , dtype ):
@@ -1769,12 +1770,12 @@ def test_basic(self, writable, dtype):
1769
1770
result = algos .rank (ser )
1770
1771
tm .assert_numpy_array_equal (result , exp )
1771
1772
1772
- def test_uint64_overflow (self ):
1773
+ @pytest .mark .parametrize ("dtype" , [np .float64 , np .uint64 ])
1774
+ def test_uint64_overflow (self , dtype ):
1773
1775
exp = np .array ([1 , 2 ], dtype = np .float64 )
1774
1776
1775
- for dtype in [np .float64 , np .uint64 ]:
1776
- s = Series ([1 , 2 ** 63 ], dtype = dtype )
1777
- tm .assert_numpy_array_equal (algos .rank (s ), exp )
1777
+ s = Series ([1 , 2 ** 63 ], dtype = dtype )
1778
+ tm .assert_numpy_array_equal (algos .rank (s ), exp )
1778
1779
1779
1780
def test_too_many_ndims (self ):
1780
1781
arr = np .array ([[[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]]])
@@ -1819,21 +1820,6 @@ def test_pad_backfill_object_segfault():
1819
1820
1820
1821
1821
1822
class TestTseriesUtil :
1822
- def test_combineFunc (self ):
1823
- pass
1824
-
1825
- def test_reindex (self ):
1826
- pass
1827
-
1828
- def test_isna (self ):
1829
- pass
1830
-
1831
- def test_groupby (self ):
1832
- pass
1833
-
1834
- def test_groupby_withnull (self ):
1835
- pass
1836
-
1837
1823
def test_backfill (self ):
1838
1824
old = Index ([1 , 5 , 10 ])
1839
1825
new = Index (list (range (12 )))
@@ -2274,44 +2260,45 @@ def test_no_mode(self):
2274
2260
exp = Series ([], dtype = np .float64 , index = Index ([], dtype = int ))
2275
2261
tm .assert_series_equal (algos .mode ([]), exp )
2276
2262
2277
- def test_mode_single (self ):
2263
+ @pytest .mark .parametrize ("dt" , np .typecodes ["AllInteger" ] + np .typecodes ["Float" ])
2264
+ def test_mode_single (self , dt ):
2278
2265
# GH 15714
2279
2266
exp_single = [1 ]
2280
2267
data_single = [1 ]
2281
2268
2282
2269
exp_multi = [1 ]
2283
2270
data_multi = [1 , 1 ]
2284
2271
2285
- for dt in np .typecodes ["AllInteger" ] + np .typecodes ["Float" ]:
2286
- s = Series (data_single , dtype = dt )
2287
- exp = Series (exp_single , dtype = dt )
2288
- tm .assert_series_equal (algos .mode (s ), exp )
2272
+ s = Series (data_single , dtype = dt )
2273
+ exp = Series (exp_single , dtype = dt )
2274
+ tm .assert_series_equal (algos .mode (s ), exp )
2289
2275
2290
- s = Series (data_multi , dtype = dt )
2291
- exp = Series (exp_multi , dtype = dt )
2292
- tm .assert_series_equal (algos .mode (s ), exp )
2276
+ s = Series (data_multi , dtype = dt )
2277
+ exp = Series (exp_multi , dtype = dt )
2278
+ tm .assert_series_equal (algos .mode (s ), exp )
2293
2279
2280
+ def test_mode_obj_int (self ):
2294
2281
exp = Series ([1 ], dtype = int )
2295
2282
tm .assert_series_equal (algos .mode ([1 ]), exp )
2296
2283
2297
2284
exp = Series (["a" , "b" , "c" ], dtype = object )
2298
2285
tm .assert_series_equal (algos .mode (["a" , "b" , "c" ]), exp )
2299
2286
2300
- def test_number_mode (self ):
2287
+ @pytest .mark .parametrize ("dt" , np .typecodes ["AllInteger" ] + np .typecodes ["Float" ])
2288
+ def test_number_mode (self , dt ):
2301
2289
exp_single = [1 ]
2302
2290
data_single = [1 ] * 5 + [2 ] * 3
2303
2291
2304
2292
exp_multi = [1 , 3 ]
2305
2293
data_multi = [1 ] * 5 + [2 ] * 3 + [3 ] * 5
2306
2294
2307
- for dt in np .typecodes ["AllInteger" ] + np .typecodes ["Float" ]:
2308
- s = Series (data_single , dtype = dt )
2309
- exp = Series (exp_single , dtype = dt )
2310
- tm .assert_series_equal (algos .mode (s ), exp )
2295
+ s = Series (data_single , dtype = dt )
2296
+ exp = Series (exp_single , dtype = dt )
2297
+ tm .assert_series_equal (algos .mode (s ), exp )
2311
2298
2312
- s = Series (data_multi , dtype = dt )
2313
- exp = Series (exp_multi , dtype = dt )
2314
- tm .assert_series_equal (algos .mode (s ), exp )
2299
+ s = Series (data_multi , dtype = dt )
2300
+ exp = Series (exp_multi , dtype = dt )
2301
+ tm .assert_series_equal (algos .mode (s ), exp )
2315
2302
2316
2303
def test_strobj_mode (self ):
2317
2304
exp = ["b" ]
@@ -2321,13 +2308,14 @@ def test_strobj_mode(self):
2321
2308
exp = Series (exp , dtype = "c" )
2322
2309
tm .assert_series_equal (algos .mode (s ), exp )
2323
2310
2311
+ @pytest .mark .parametrize ("dt" , [str , object ])
2312
+ def test_strobj_multi_char (self , dt ):
2324
2313
exp = ["bar" ]
2325
2314
data = ["foo" ] * 2 + ["bar" ] * 3
2326
2315
2327
- for dt in [str , object ]:
2328
- s = Series (data , dtype = dt )
2329
- exp = Series (exp , dtype = dt )
2330
- tm .assert_series_equal (algos .mode (s ), exp )
2316
+ s = Series (data , dtype = dt )
2317
+ exp = Series (exp , dtype = dt )
2318
+ tm .assert_series_equal (algos .mode (s ), exp )
2331
2319
2332
2320
def test_datelike_mode (self ):
2333
2321
exp = Series (["1900-05-03" , "2011-01-03" , "2013-01-02" ], dtype = "M8[ns]" )
0 commit comments