Skip to content

CLN: Unify string storage fixture usage #50290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,7 @@ def string_dtype(request):
@pytest.fixture(
params=[
"string[python]",
pytest.param(
"string[pyarrow]", marks=td.skip_if_no("pyarrow", min_version="1.0.0")
),
pytest.param("string[pyarrow]", marks=td.skip_if_no("pyarrow")),
]
)
def nullable_string_dtype(request):
Expand All @@ -1289,7 +1287,7 @@ def nullable_string_dtype(request):
@pytest.fixture(
params=[
"python",
pytest.param("pyarrow", marks=td.skip_if_no("pyarrow", min_version="1.0.0")),
pytest.param("pyarrow", marks=td.skip_if_no("pyarrow")),
]
)
def string_storage(request):
Expand Down Expand Up @@ -1332,9 +1330,7 @@ def object_dtype(request):
params=[
"object",
"string[python]",
pytest.param(
"string[pyarrow]", marks=td.skip_if_no("pyarrow", min_version="1.0.0")
),
pytest.param("string[pyarrow]", marks=td.skip_if_no("pyarrow")),
]
)
def any_string_dtype(request):
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,15 +600,14 @@ def test_use_nullabla_dtypes_and_dtype(self, read_ext):
tm.assert_frame_equal(result, df)

@td.skip_if_no("pyarrow")
@pytest.mark.parametrize("storage", ["pyarrow", "python"])
def test_use_nullable_dtypes_string(self, read_ext, storage):
def test_use_nullable_dtypes_string(self, read_ext, string_storage):
# GH#36712
if read_ext in (".xlsb", ".xls"):
pytest.skip(f"No engine for filetype: '{read_ext}'")

import pyarrow as pa

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):

df = DataFrame(
{
Expand All @@ -622,7 +621,7 @@ def test_use_nullable_dtypes_string(self, read_ext, storage):
file_path, sheet_name="test", use_nullable_dtypes=True
)

if storage == "python":
if string_storage == "python":
expected = DataFrame(
{
"a": StringArray(np.array(["a", "b"], dtype=np.object_)),
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/io/parser/dtypes/test_dtypes_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,11 @@ def test_use_nullabla_dtypes_and_dtype(all_parsers):


@pytest.mark.usefixtures("pyarrow_xfail")
@pytest.mark.parametrize("storage", ["pyarrow", "python"])
def test_use_nullable_dtypes_string(all_parsers, storage):
def test_use_nullable_dtypes_string(all_parsers, string_storage):
# GH#36712
pa = pytest.importorskip("pyarrow")

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):

parser = all_parsers

Expand All @@ -461,7 +460,7 @@ def test_use_nullable_dtypes_string(all_parsers, storage):
"""
result = parser.read_csv(StringIO(data), use_nullable_dtypes=True)

if storage == "python":
if string_storage == "python":
expected = DataFrame(
{
"a": StringArray(np.array(["a", "b"], dtype=np.object_)),
Expand Down
7 changes: 3 additions & 4 deletions pandas/tests/io/parser/test_upcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@ def test_maybe_upcaste_all_nan():


@td.skip_if_no("pyarrow")
@pytest.mark.parametrize("storage", ["pyarrow", "python"])
@pytest.mark.parametrize("val", [na_values[np.object_], "c"])
def test_maybe_upcast_object(val, storage):
def test_maybe_upcast_object(val, string_storage):
# GH#36712
import pyarrow as pa

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):
arr = np.array(["a", "b", val], dtype=np.object_)
result = _maybe_upcast(arr, use_nullable_dtypes=True)

if storage == "python":
if string_storage == "python":
exp_val = "c" if val == "c" else NA
expected = StringArray(np.array(["a", "b", exp_val], dtype=np.object_))
else:
Expand Down
25 changes: 11 additions & 14 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2276,51 +2276,49 @@ def test_get_engine_auto_error_message(self):
pass
# TODO(GH#36893) fill this in when we add more engines

@pytest.mark.parametrize("storage", ["pyarrow", "python"])
def test_read_sql_nullable_dtypes(self, storage):
def test_read_sql_nullable_dtypes(self, string_storage):
# GH#50048
table = "test"
df = self.nullable_data()
df.to_sql(table, self.conn, index=False, if_exists="replace")

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):
result = pd.read_sql(
f"Select * from {table}", self.conn, use_nullable_dtypes=True
)
expected = self.nullable_expected(storage)
expected = self.nullable_expected(string_storage)
tm.assert_frame_equal(result, expected)

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):
iterator = pd.read_sql(
f"Select * from {table}",
self.conn,
use_nullable_dtypes=True,
chunksize=3,
)
expected = self.nullable_expected(storage)
expected = self.nullable_expected(string_storage)
for result in iterator:
tm.assert_frame_equal(result, expected)

@pytest.mark.parametrize("storage", ["pyarrow", "python"])
def test_read_sql_nullable_dtypes_table(self, storage):
def test_read_sql_nullable_dtypes_table(self, string_storage):
# GH#50048
table = "test"
df = self.nullable_data()
df.to_sql(table, self.conn, index=False, if_exists="replace")

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):
result = pd.read_sql(table, self.conn, use_nullable_dtypes=True)
expected = self.nullable_expected(storage)
expected = self.nullable_expected(string_storage)
tm.assert_frame_equal(result, expected)

with pd.option_context("mode.string_storage", storage):
with pd.option_context("mode.string_storage", string_storage):
iterator = pd.read_sql(
f"Select * from {table}",
self.conn,
use_nullable_dtypes=True,
chunksize=3,
)
expected = self.nullable_expected(storage)
expected = self.nullable_expected(string_storage)
for result in iterator:
tm.assert_frame_equal(result, expected)

Expand Down Expand Up @@ -2450,8 +2448,7 @@ class Test(BaseModel):
def nullable_expected(self, storage) -> DataFrame:
return super().nullable_expected(storage).astype({"e": "Int64", "f": "Int64"})

@pytest.mark.parametrize("storage", ["pyarrow", "python"])
def test_read_sql_nullable_dtypes_table(self, storage):
def test_read_sql_nullable_dtypes_table(self, string_storage):
# GH#50048 Not supported for sqlite
pass

Expand Down
4 changes: 0 additions & 4 deletions pandas/tests/plotting/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import pandas._config.config as cf

import pandas.util._test_decorators as td

from pandas import (
Index,
Period,
Expand Down Expand Up @@ -76,7 +74,6 @@ def test_dont_register_by_default(self):
call = [sys.executable, "-c", code]
assert subprocess.check_call(call) == 0

@td.skip_if_no("matplotlib", min_version="3.1.3")
def test_registering_no_warning(self):
plt = pytest.importorskip("matplotlib.pyplot")
s = Series(range(12), index=date_range("2017", periods=12))
Expand Down Expand Up @@ -111,7 +108,6 @@ def test_matplotlib_formatters(self):
assert Timestamp not in units.registry
assert Timestamp in units.registry

@td.skip_if_no("matplotlib", min_version="3.1.3")
def test_option_no_warning(self):
pytest.importorskip("matplotlib.pyplot")
ctx = cf.option_context("plotting.matplotlib.register_converters", False)
Expand Down