Skip to content

Commit

Permalink
fix tests for object-dtype fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Nov 7, 2024
1 parent 1281edd commit b5b2fe2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
36 changes: 23 additions & 13 deletions pandas/tests/frame/methods/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import numpy as np
import pytest

from pandas._config import using_string_dtype

from pandas.compat import (
HAS_PYARROW,
IS64,
Expand Down Expand Up @@ -436,18 +434,25 @@ def test_usage_via_getsizeof():
assert abs(diff) < 100


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
def test_info_memory_usage_qualified():
def test_info_memory_usage_qualified(using_infer_string):
buf = StringIO()
df = DataFrame(1, columns=list("ab"), index=[1, 2, 3])
df.info(buf=buf)
assert "+" not in buf.getvalue()

buf = StringIO()
df = DataFrame(1, columns=list("ab"), index=list("ABC"))
df = DataFrame(1, columns=list("ab"), index=Index(list("ABC"), dtype=object))
df.info(buf=buf)
assert "+" in buf.getvalue()

buf = StringIO()
df = DataFrame(1, columns=list("ab"), index=Index(list("ABC"), dtype="str"))
df.info(buf=buf)
if using_infer_string and HAS_PYARROW:
assert "+" not in buf.getvalue()
else:
assert "+" in buf.getvalue()

buf = StringIO()
df = DataFrame(
1, columns=list("ab"), index=MultiIndex.from_product([range(3), range(3)])
Expand All @@ -460,7 +465,10 @@ def test_info_memory_usage_qualified():
1, columns=list("ab"), index=MultiIndex.from_product([range(3), ["foo", "bar"]])
)
df.info(buf=buf)
assert "+" in buf.getvalue()
if using_infer_string and HAS_PYARROW:
assert "+" not in buf.getvalue()
else:
assert "+" in buf.getvalue()


def test_info_memory_usage_bug_on_multiindex():
Expand Down Expand Up @@ -497,16 +505,15 @@ def test_info_categorical():
df.info(buf=buf)


@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)")
@pytest.mark.xfail(not IS64, reason="GH 36579: fail on 32-bit system")
def test_info_int_columns():
def test_info_int_columns(using_infer_string):
# GH#37245
df = DataFrame({1: [1, 2], 2: [2, 3]}, index=["A", "B"])
buf = StringIO()
df.info(show_counts=True, buf=buf)
result = buf.getvalue()
expected = textwrap.dedent(
"""\
f"""\
<class 'pandas.DataFrame'>
Index: 2 entries, A to B
Data columns (total 2 columns):
Expand All @@ -515,19 +522,22 @@ def test_info_int_columns():
0 1 2 non-null int64
1 2 2 non-null int64
dtypes: int64(2)
memory usage: 48.0+ bytes
memory usage: {'50.0' if using_infer_string and HAS_PYARROW else '48.0+'} bytes
"""
)
assert result == expected


@pytest.mark.xfail(using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)")
def test_memory_usage_empty_no_warning():
def test_memory_usage_empty_no_warning(using_infer_string):
# GH#50066
df = DataFrame(index=["a", "b"])
with tm.assert_produces_warning(None):
result = df.memory_usage()
expected = Series(16 if IS64 else 8, index=["Index"])
if using_infer_string and HAS_PYARROW:
value = 18
else:
value = 16 if IS64 else 8
expected = Series(value, index=["Index"])
tm.assert_series_equal(result, expected)


Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/series/methods/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ def test_info_series(
10 non-null int64
"""
)
qualifier = "" if using_infer_string and HAS_PYARROW else "+"
expected += textwrap.dedent(
f"""\
dtypes: int64(1)
memory usage: {ser.memory_usage()}.0{'' if using_infer_string else '+'} bytes
memory usage: {ser.memory_usage()}.0{qualifier} bytes
"""
)
assert result == expected
Expand Down

0 comments on commit b5b2fe2

Please sign in to comment.