Skip to content

Commit c2e6ab0

Browse files
committed
Fix test_string_inference for feather
1 parent fc066f4 commit c2e6ab0

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pandas/tests/io/test_feather.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import numpy as np
77
import pytest
88

9-
from pandas.compat.pyarrow import pa_version_under18p0
9+
from pandas.compat.pyarrow import (
10+
pa_version_under18p0,
11+
pa_version_under19p0,
12+
)
1013

1114
import pandas as pd
1215
import pandas._testing as tm
@@ -239,16 +242,27 @@ def test_invalid_dtype_backend(self):
239242
with pytest.raises(ValueError, match=msg):
240243
read_feather(path, dtype_backend="numpy")
241244

242-
def test_string_inference(self, tmp_path):
245+
def test_string_inference(self, tmp_path, using_infer_string):
243246
# GH#54431
244247
path = tmp_path / "test_string_inference.p"
245248
df = pd.DataFrame(data={"a": ["x", "y"]})
246249
df.to_feather(path)
247250
with pd.option_context("future.infer_string", True):
248251
result = read_feather(path)
252+
dtype = pd.StringDtype(na_value=np.nan)
249253
expected = pd.DataFrame(
250254
data={"a": ["x", "y"]}, dtype=pd.StringDtype(na_value=np.nan)
251255
)
256+
expected = pd.DataFrame(
257+
data={"a": ["x", "y"]},
258+
dtype=dtype,
259+
columns=pd.Index(
260+
["a"],
261+
dtype=object
262+
if pa_version_under19p0 and not using_infer_string
263+
else dtype,
264+
),
265+
)
252266
tm.assert_frame_equal(result, expected)
253267

254268
@pytest.mark.skipif(pa_version_under18p0, reason="not supported before 18.0")

pandas/tests/io/test_parquet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ def test_string_inference(self, tmp_path, pa, using_infer_string):
11161116
df = pd.DataFrame(data={"a": ["x", "y"]}, index=["a", "b"])
11171117
df.to_parquet(path, engine=pa)
11181118
with pd.option_context("future.infer_string", True):
1119-
result = read_parquet(path, engine="pyarrow")
1119+
result = read_parquet(path, engine=pa)
11201120
dtype = pd.StringDtype(na_value=np.nan)
11211121
expected = pd.DataFrame(
11221122
data={"a": ["x", "y"]},

0 commit comments

Comments
 (0)