Skip to content

Commit b5b2fe2

Browse files
fix tests for object-dtype fallback
1 parent 1281edd commit b5b2fe2

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

pandas/tests/frame/methods/test_info.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import numpy as np
88
import pytest
99

10-
from pandas._config import using_string_dtype
11-
1210
from pandas.compat import (
1311
HAS_PYARROW,
1412
IS64,
@@ -436,18 +434,25 @@ def test_usage_via_getsizeof():
436434
assert abs(diff) < 100
437435

438436

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):
441438
buf = StringIO()
442439
df = DataFrame(1, columns=list("ab"), index=[1, 2, 3])
443440
df.info(buf=buf)
444441
assert "+" not in buf.getvalue()
445442

446443
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))
448445
df.info(buf=buf)
449446
assert "+" in buf.getvalue()
450447

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+
451456
buf = StringIO()
452457
df = DataFrame(
453458
1, columns=list("ab"), index=MultiIndex.from_product([range(3), range(3)])
@@ -460,7 +465,10 @@ def test_info_memory_usage_qualified():
460465
1, columns=list("ab"), index=MultiIndex.from_product([range(3), ["foo", "bar"]])
461466
)
462467
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()
464472

465473

466474
def test_info_memory_usage_bug_on_multiindex():
@@ -497,16 +505,15 @@ def test_info_categorical():
497505
df.info(buf=buf)
498506

499507

500-
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
501508
@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):
503510
# GH#37245
504511
df = DataFrame({1: [1, 2], 2: [2, 3]}, index=["A", "B"])
505512
buf = StringIO()
506513
df.info(show_counts=True, buf=buf)
507514
result = buf.getvalue()
508515
expected = textwrap.dedent(
509-
"""\
516+
f"""\
510517
<class 'pandas.DataFrame'>
511518
Index: 2 entries, A to B
512519
Data columns (total 2 columns):
@@ -515,19 +522,22 @@ def test_info_int_columns():
515522
0 1 2 non-null int64
516523
1 2 2 non-null int64
517524
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
519526
"""
520527
)
521528
assert result == expected
522529

523530

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):
526532
# GH#50066
527533
df = DataFrame(index=["a", "b"])
528534
with tm.assert_produces_warning(None):
529535
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"])
531541
tm.assert_series_equal(result, expected)
532542

533543

pandas/tests/series/methods/test_info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ def test_info_series(
6969
10 non-null int64
7070
"""
7171
)
72+
qualifier = "" if using_infer_string and HAS_PYARROW else "+"
7273
expected += textwrap.dedent(
7374
f"""\
7475
dtypes: int64(1)
75-
memory usage: {ser.memory_usage()}.0{'' if using_infer_string else '+'} bytes
76+
memory usage: {ser.memory_usage()}.0{qualifier} bytes
7677
"""
7778
)
7879
assert result == expected

0 commit comments

Comments
 (0)