@@ -354,71 +354,69 @@ def test_is_recompilable_fails(ll):
354
354
355
355
356
356
class TestInference :
357
- def test_infer_dtype_bytes (self ):
358
- compare = "bytes"
359
-
360
- # string array of bytes
361
- arr = np .array (list ("abc" ), dtype = "S1" )
362
- assert lib .infer_dtype (arr , skipna = True ) == compare
357
+ @pytest .mark .parametrize (
358
+ "arr" ,
359
+ [
360
+ np .array (list ("abc" ), dtype = "S1" ),
361
+ np .array (list ("abc" ), dtype = "S1" ).astype (object ),
362
+ [b"a" , np .nan , b"c" ],
363
+ ],
364
+ )
365
+ def test_infer_dtype_bytes (self , arr ):
366
+ result = lib .infer_dtype (arr , skipna = True )
367
+ assert result == "bytes"
363
368
364
- # object array of bytes
365
- arr = arr .astype (object )
366
- assert lib .infer_dtype (arr , skipna = True ) == compare
369
+ @pytest .mark .parametrize (
370
+ "value, expected" ,
371
+ [
372
+ (float ("inf" ), True ),
373
+ (np .inf , True ),
374
+ (- np .inf , False ),
375
+ (1 , False ),
376
+ ("a" , False ),
377
+ ],
378
+ )
379
+ def test_isposinf_scalar (self , value , expected ):
380
+ # GH 11352
381
+ result = libmissing .isposinf_scalar (value )
382
+ assert result is expected
367
383
368
- # object array of bytes with missing values
369
- assert lib .infer_dtype ([b"a" , np .nan , b"c" ], skipna = True ) == compare
384
+ @pytest .mark .parametrize (
385
+ "value, expected" ,
386
+ [
387
+ (float ("-inf" ), True ),
388
+ (- np .inf , True ),
389
+ (np .inf , False ),
390
+ (1 , False ),
391
+ ("a" , False ),
392
+ ],
393
+ )
394
+ def test_isneginf_scalar (self , value , expected ):
395
+ result = libmissing .isneginf_scalar (value )
396
+ assert result is expected
370
397
371
- def test_isinf_scalar (self ):
372
- # GH 11352
373
- assert libmissing .isposinf_scalar (float ("inf" ))
374
- assert libmissing .isposinf_scalar (np .inf )
375
- assert not libmissing .isposinf_scalar (- np .inf )
376
- assert not libmissing .isposinf_scalar (1 )
377
- assert not libmissing .isposinf_scalar ("a" )
378
-
379
- assert libmissing .isneginf_scalar (float ("-inf" ))
380
- assert libmissing .isneginf_scalar (- np .inf )
381
- assert not libmissing .isneginf_scalar (np .inf )
382
- assert not libmissing .isneginf_scalar (1 )
383
- assert not libmissing .isneginf_scalar ("a" )
384
-
385
- @pytest .mark .parametrize ("maybe_int" , [True , False ])
398
+ @pytest .mark .parametrize ("coerce_numeric" , [True , False ])
386
399
@pytest .mark .parametrize (
387
400
"infinity" , ["inf" , "inF" , "iNf" , "Inf" , "iNF" , "InF" , "INf" , "INF" ]
388
401
)
389
- def test_maybe_convert_numeric_infinities (self , infinity , maybe_int ):
402
+ @pytest .mark .parametrize ("prefix" , ["" , "-" , "+" ])
403
+ def test_maybe_convert_numeric_infinities (self , coerce_numeric , infinity , prefix ):
390
404
# see gh-13274
391
- na_values = {"" , "NULL" , "nan" }
392
-
393
- pos = np .array (["inf" ], dtype = np .float64 )
394
- neg = np .array (["-inf" ], dtype = np .float64 )
395
-
396
- msg = "Unable to parse string"
397
-
398
- out = lib .maybe_convert_numeric (
399
- np .array ([infinity ], dtype = object ), na_values , maybe_int
400
- )
401
- tm .assert_numpy_array_equal (out , pos )
402
-
403
- out = lib .maybe_convert_numeric (
404
- np .array (["-" + infinity ], dtype = object ), na_values , maybe_int
405
- )
406
- tm .assert_numpy_array_equal (out , neg )
407
-
408
- out = lib .maybe_convert_numeric (
409
- np .array ([infinity ], dtype = object ), na_values , maybe_int
410
- )
411
- tm .assert_numpy_array_equal (out , pos )
412
-
413
- out = lib .maybe_convert_numeric (
414
- np .array (["+" + infinity ], dtype = object ), na_values , maybe_int
405
+ result = lib .maybe_convert_numeric (
406
+ np .array ([prefix + infinity ], dtype = object ),
407
+ na_values = {"" , "NULL" , "nan" },
408
+ coerce_numeric = coerce_numeric ,
415
409
)
416
- tm .assert_numpy_array_equal (out , pos )
410
+ expected = np .array ([np .inf if prefix in ["" , "+" ] else - np .inf ])
411
+ tm .assert_numpy_array_equal (result , expected )
417
412
418
- # too many characters
413
+ def test_maybe_convert_numeric_infinities_raises (self ):
414
+ msg = "Unable to parse string"
419
415
with pytest .raises (ValueError , match = msg ):
420
416
lib .maybe_convert_numeric (
421
- np .array (["foo_" + infinity ], dtype = object ), na_values , maybe_int
417
+ np .array (["foo_inf" ], dtype = object ),
418
+ na_values = {"" , "NULL" , "nan" },
419
+ coerce_numeric = False ,
422
420
)
423
421
424
422
def test_maybe_convert_numeric_post_floatify_nan (self , coerce ):
0 commit comments