MCPcopy
hub / github.com/pandas-dev/pandas / func

Function func

pandas/tests/io/test_sql.py:3732–3770  ·  view source on GitHub ↗
(string_storage, dtype_backend, conn_name)

Source from the content-addressed store, hash-verified

3730@pytest.fixture
3731def dtype_backend_expected():
3732 def func(string_storage, dtype_backend, conn_name) -> DataFrame:
3733 string_dtype: pd.StringDtype | pd.ArrowDtype
3734 if dtype_backend == "pyarrow":
3735 pa = pytest.importorskip("pyarrow")
3736 string_dtype = pd.ArrowDtype(pa.string())
3737 else:
3738 string_dtype = pd.StringDtype(string_storage)
3739
3740 df = DataFrame(
3741 {
3742 "a": Series([1, pd.NA, 3], dtype="Int64"),
3743 "b": Series([1, 2, 3], dtype="Int64"),
3744 "c": Series([1.5, pd.NA, 2.5], dtype="Float64"),
3745 "d": Series([1.5, 2.0, 2.5], dtype="Float64"),
3746 "e": Series([True, False, pd.NA], dtype="boolean"),
3747 "f": Series([True, False, True], dtype="boolean"),
3748 "g": Series(["a", "b", "c"], dtype=string_dtype),
3749 "h": Series(["a", "b", None], dtype=string_dtype),
3750 }
3751 )
3752 if dtype_backend == "pyarrow":
3753 pa = pytest.importorskip("pyarrow")
3754
3755 from pandas.arrays import ArrowExtensionArray
3756
3757 df = DataFrame(
3758 {
3759 col: ArrowExtensionArray(pa.array(df[col], from_pandas=True))
3760 for col in df.columns
3761 }
3762 )
3763
3764 if "mysql" in conn_name or "sqlite" in conn_name:
3765 if dtype_backend == "numpy_nullable":
3766 df = df.astype({"e": "Int64", "f": "Int64"})
3767 else:
3768 df = df.astype({"e": "int64[pyarrow]", "f": "int64[pyarrow]"})
3769
3770 return df
3771
3772 return func
3773

Calls 6

DataFrameClass · 0.90
SeriesClass · 0.90
ArrowExtensionArrayClass · 0.90
stringMethod · 0.80
arrayMethod · 0.45
astypeMethod · 0.45

Tested by

no test coverage detected