Skip to content

nightly fix for GH-657 #660

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 6 commits into from
Apr 26, 2023
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
34 changes: 22 additions & 12 deletions tests/test_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,20 @@ def test_is_object_dtype() -> None:


def test_is_period_dtype() -> None:
check(assert_type(api.is_period_dtype(arr), bool), bool)
check(assert_type(api.is_period_dtype(nparr), bool), bool)
check(assert_type(api.is_period_dtype(dtylike), bool), bool)
check(
assert_type(api.is_period_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_period_dtype(ind), bool), bool)
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)
with pytest_warns_bounded(
FutureWarning,
match="is_period_dtype is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_period_dtype(arr), bool), bool)
check(assert_type(api.is_period_dtype(nparr), bool), bool)
check(assert_type(api.is_period_dtype(dtylike), bool), bool)
check(
assert_type(api.is_period_dtype(dframe), bool),
bool,
)
check(assert_type(api.is_period_dtype(ind), bool), bool)
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)


def test_is_re() -> None:
Expand Down Expand Up @@ -416,9 +421,14 @@ def test_is_signed_integer_dtype() -> None:


def test_is_sparse() -> None:
check(assert_type(api.is_sparse(arr), bool), bool)
check(assert_type(api.is_sparse(nparr), bool), bool)
check(assert_type(api.is_sparse(dframe), bool), bool)
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(api.is_sparse(arr), bool), bool)
check(assert_type(api.is_sparse(nparr), bool), bool)
check(assert_type(api.is_sparse(dframe), bool), bool)


def test_is_string_dtype() -> None:
Expand Down
36 changes: 23 additions & 13 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,17 +1098,22 @@ def test_to_markdown() -> None:
def test_types_to_feather() -> None:
pytest.importorskip("pyarrow")
df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]})
with ensure_clean() as path:
df.to_feather(path)
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
with ensure_clean() as path:
df.to_feather(path)
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)

# to_feather has been able to accept a buffer since pandas 1.0.0
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
# Docstring and type were updated in 1.2.0.
# https://github.com/pandas-dev/pandas/pull/35408
with open(path, mode="wb") as file:
df.to_feather(file)
# to_feather has been able to accept a buffer since pandas 1.0.0
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
# Docstring and type were updated in 1.2.0.
# https://github.com/pandas-dev/pandas/pull/35408
with open(path, mode="wb") as file:
df.to_feather(file)


# compare() method added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
Expand Down Expand Up @@ -1339,9 +1344,14 @@ def test_types_to_parquet() -> None:
allows_duplicate_labels=False
)
with ensure_clean() as path:
df.to_parquet(Path(path))
# to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
b: bytes = df.to_parquet()
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
df.to_parquet(Path(path))
# to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
b: bytes = df.to_parquet()


def test_types_to_latex() -> None:
Expand Down
91 changes: 74 additions & 17 deletions tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@
from pandas.io.sas.sas_xport import XportReader
from pandas.io.stata import StataReader

from . import lxml_skip
from . import (
lxml_skip,
pytest_warns_bounded,
)

DF = DataFrame({"a": [1, 2, 3], "b": [0.0, 0.0, 0.0]})
CWD = os.path.split(os.path.abspath(__file__))[0]
Expand All @@ -78,23 +81,38 @@
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc():
with ensure_clean() as path:
check(assert_type(DF.to_orc(path), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_orc(path), None), type(None))
check(assert_type(read_orc(path), DataFrame), DataFrame)


@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc_path():
with ensure_clean() as path:
pathlib_path = Path(path)
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)


@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc_buffer():
with ensure_clean() as path:
file_w = open(path, "wb")
check(assert_type(DF.to_orc(file_w), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_orc(file_w), None), type(None))
file_w.close()

file_r = open(path, "rb")
Expand All @@ -105,13 +123,23 @@ def test_orc_buffer():
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc_columns():
with ensure_clean() as path:
check(assert_type(DF.to_orc(path, index=False), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_orc(path, index=False), None), type(None))
check(assert_type(read_orc(path, columns=["a"]), DataFrame), DataFrame)


@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
def test_orc_bytes():
check(assert_type(DF.to_orc(index=False), bytes), bytes)
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_orc(index=False), bytes), bytes)


@lxml_skip
Expand Down Expand Up @@ -504,27 +532,47 @@ def test_json_chunk():

def test_parquet():
with ensure_clean() as path:
check(assert_type(DF.to_parquet(path), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_parquet(path), None), type(None))
check(assert_type(DF.to_parquet(), bytes), bytes)
check(assert_type(read_parquet(path), DataFrame), DataFrame)
check(assert_type(DF.to_parquet(), bytes), bytes)


def test_parquet_options():
with ensure_clean(".parquet") as path:
check(
assert_type(DF.to_parquet(path, compression=None, index=True), None),
type(None),
)
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(
assert_type(DF.to_parquet(path, compression=None, index=True), None),
type(None),
)
check(assert_type(read_parquet(path), DataFrame), DataFrame)


def test_feather():
with ensure_clean() as path:
check(assert_type(DF.to_feather(path), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_feather(path), None), type(None))
check(assert_type(read_feather(path), DataFrame), DataFrame)
check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame)
bio = io.BytesIO()
check(assert_type(DF.to_feather(bio), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.00",
):
check(assert_type(DF.to_feather(bio), None), type(None))
bio.seek(0)
check(assert_type(read_feather(bio), DataFrame), DataFrame)

Expand Down Expand Up @@ -1322,13 +1370,22 @@ def test_all_read_without_lxml_dtype_backend() -> None:
con.close()

if not WINDOWS:
check(assert_type(DF.to_orc(path), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_orc(path), None), type(None))
check(
assert_type(read_orc(path, dtype_backend="numpy_nullable"), DataFrame),
DataFrame,
)

check(assert_type(DF.to_feather(path), None), type(None))
with pytest_warns_bounded(
FutureWarning,
match="is_sparse is deprecated and will be removed in a future version",
lower="2.0.99",
):
check(assert_type(DF.to_feather(path), None), type(None))
check(
assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame),
DataFrame,
Expand Down