7
7
import numpy as np
8
8
import pytest
9
9
10
- from pandas ._config import using_string_dtype
11
-
12
10
from pandas .compat import (
13
11
HAS_PYARROW ,
14
12
IS64 ,
@@ -436,18 +434,25 @@ def test_usage_via_getsizeof():
436
434
assert abs (diff ) < 100
437
435
438
436
439
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
440
- def test_info_memory_usage_qualified ():
437
+ def test_info_memory_usage_qualified (using_infer_string ):
441
438
buf = StringIO ()
442
439
df = DataFrame (1 , columns = list ("ab" ), index = [1 , 2 , 3 ])
443
440
df .info (buf = buf )
444
441
assert "+" not in buf .getvalue ()
445
442
446
443
buf = StringIO ()
447
- df = DataFrame (1 , columns = list ("ab" ), index = list ("ABC" ))
444
+ df = DataFrame (1 , columns = list ("ab" ), index = Index ( list ("ABC" ), dtype = object ))
448
445
df .info (buf = buf )
449
446
assert "+" in buf .getvalue ()
450
447
448
+ buf = StringIO ()
449
+ df = DataFrame (1 , columns = list ("ab" ), index = Index (list ("ABC" ), dtype = "str" ))
450
+ df .info (buf = buf )
451
+ if using_infer_string and HAS_PYARROW :
452
+ assert "+" not in buf .getvalue ()
453
+ else :
454
+ assert "+" in buf .getvalue ()
455
+
451
456
buf = StringIO ()
452
457
df = DataFrame (
453
458
1 , columns = list ("ab" ), index = MultiIndex .from_product ([range (3 ), range (3 )])
@@ -460,7 +465,10 @@ def test_info_memory_usage_qualified():
460
465
1 , columns = list ("ab" ), index = MultiIndex .from_product ([range (3 ), ["foo" , "bar" ]])
461
466
)
462
467
df .info (buf = buf )
463
- assert "+" in buf .getvalue ()
468
+ if using_infer_string and HAS_PYARROW :
469
+ assert "+" not in buf .getvalue ()
470
+ else :
471
+ assert "+" in buf .getvalue ()
464
472
465
473
466
474
def test_info_memory_usage_bug_on_multiindex ():
@@ -497,16 +505,15 @@ def test_info_categorical():
497
505
df .info (buf = buf )
498
506
499
507
500
- @pytest .mark .xfail (using_string_dtype (), reason = "TODO(infer_string)" )
501
508
@pytest .mark .xfail (not IS64 , reason = "GH 36579: fail on 32-bit system" )
502
- def test_info_int_columns ():
509
+ def test_info_int_columns (using_infer_string ):
503
510
# GH#37245
504
511
df = DataFrame ({1 : [1 , 2 ], 2 : [2 , 3 ]}, index = ["A" , "B" ])
505
512
buf = StringIO ()
506
513
df .info (show_counts = True , buf = buf )
507
514
result = buf .getvalue ()
508
515
expected = textwrap .dedent (
509
- """\
516
+ f """\
510
517
<class 'pandas.DataFrame'>
511
518
Index: 2 entries, A to B
512
519
Data columns (total 2 columns):
@@ -515,19 +522,22 @@ def test_info_int_columns():
515
522
0 1 2 non-null int64
516
523
1 2 2 non-null int64
517
524
dtypes: int64(2)
518
- memory usage: 48.0+ bytes
525
+ memory usage: { '50.0' if using_infer_string and HAS_PYARROW else ' 48.0+' } bytes
519
526
"""
520
527
)
521
528
assert result == expected
522
529
523
530
524
- @pytest .mark .xfail (using_string_dtype () and HAS_PYARROW , reason = "TODO(infer_string)" )
525
- def test_memory_usage_empty_no_warning ():
531
+ def test_memory_usage_empty_no_warning (using_infer_string ):
526
532
# GH#50066
527
533
df = DataFrame (index = ["a" , "b" ])
528
534
with tm .assert_produces_warning (None ):
529
535
result = df .memory_usage ()
530
- expected = Series (16 if IS64 else 8 , index = ["Index" ])
536
+ if using_infer_string and HAS_PYARROW :
537
+ value = 18
538
+ else :
539
+ value = 16 if IS64 else 8
540
+ expected = Series (value , index = ["Index" ])
531
541
tm .assert_series_equal (result , expected )
532
542
533
543
0 commit comments