@@ -422,20 +422,6 @@ def test_to_records_with_inf_record(self):
422
422
result = repr (df )
423
423
assert result == expected
424
424
425
- def test_masked_ea_with_formatter (self ):
426
- # GH#39336
427
- df = DataFrame (
428
- {
429
- "a" : Series ([0.123456789 , 1.123456789 ], dtype = "Float64" ),
430
- "b" : Series ([1 , 2 ], dtype = "Int64" ),
431
- }
432
- )
433
- result = df .to_string (formatters = ["{:.2f}" .format , "{:.2f}" .format ])
434
- expected = """ a b
435
- 0 0.12 1.00
436
- 1 1.12 2.00"""
437
- assert result == expected
438
-
439
425
def test_repr_ea_columns (self , any_string_dtype ):
440
426
# GH#54797
441
427
pytest .importorskip ("pyarrow" )
@@ -446,3 +432,39 @@ def test_repr_ea_columns(self, any_string_dtype):
446
432
1 2 5
447
433
2 3 6"""
448
434
assert repr (df ) == expected
435
+
436
+
437
+ @pytest .mark .parametrize (
438
+ "data,output" ,
439
+ [
440
+ ([2 , complex ("nan" ), 1 ], [" 2.0+0.0j" , " NaN+0.0j" , " 1.0+0.0j" ]),
441
+ ([2 , complex ("nan" ), - 1 ], [" 2.0+0.0j" , " NaN+0.0j" , "-1.0+0.0j" ]),
442
+ ([- 2 , complex ("nan" ), - 1 ], ["-2.0+0.0j" , " NaN+0.0j" , "-1.0+0.0j" ]),
443
+ ([- 1.23j , complex ("nan" ), - 1 ], ["-0.00-1.23j" , " NaN+0.00j" , "-1.00+0.00j" ]),
444
+ ([1.23j , complex ("nan" ), 1.23 ], [" 0.00+1.23j" , " NaN+0.00j" , " 1.23+0.00j" ]),
445
+ (
446
+ [- 1.23j , complex (np .nan , np .nan ), 1 ],
447
+ ["-0.00-1.23j" , " NaN+ NaNj" , " 1.00+0.00j" ],
448
+ ),
449
+ (
450
+ [- 1.23j , complex (1.2 , np .nan ), 1 ],
451
+ ["-0.00-1.23j" , " 1.20+ NaNj" , " 1.00+0.00j" ],
452
+ ),
453
+ (
454
+ [- 1.23j , complex (np .nan , - 1.2 ), 1 ],
455
+ ["-0.00-1.23j" , " NaN-1.20j" , " 1.00+0.00j" ],
456
+ ),
457
+ ],
458
+ )
459
+ @pytest .mark .parametrize ("as_frame" , [True , False ])
460
+ def test_repr_with_complex_nans (data , output , as_frame ):
461
+ # GH#53762, GH#53841
462
+ obj = Series (np .array (data ))
463
+ if as_frame :
464
+ obj = obj .to_frame (name = "val" )
465
+ reprs = [f"{ i } { val } " for i , val in enumerate (output )]
466
+ expected = f"{ 'val' : >{len (reprs [0 ])}} \n " + "\n " .join (reprs )
467
+ else :
468
+ reprs = [f"{ i } { val } " for i , val in enumerate (output )]
469
+ expected = "\n " .join (reprs ) + "\n dtype: complex128"
470
+ assert str (obj ) == expected , f"\n { str (obj )} \n \n { expected } "
0 commit comments