Skip to content

Commit b667761

Browse files
authored
nightly fix for GH-657 (#660)
* nightly fix for GH-657 * warning message updated * lower changed * Update test_frame.py * changed the `match` message * updated the lower values
1 parent ca27446 commit b667761

File tree

3 files changed

+119
-42
lines changed

3 files changed

+119
-42
lines changed

tests/test_api_types.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,20 @@ def test_is_object_dtype() -> None:
362362

363363

364364
def test_is_period_dtype() -> None:
365-
check(assert_type(api.is_period_dtype(arr), bool), bool)
366-
check(assert_type(api.is_period_dtype(nparr), bool), bool)
367-
check(assert_type(api.is_period_dtype(dtylike), bool), bool)
368-
check(
369-
assert_type(api.is_period_dtype(dframe), bool),
370-
bool,
371-
)
372-
check(assert_type(api.is_period_dtype(ind), bool), bool)
373-
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)
365+
with pytest_warns_bounded(
366+
FutureWarning,
367+
match="is_period_dtype is deprecated and will be removed in a future version",
368+
lower="2.0.99",
369+
):
370+
check(assert_type(api.is_period_dtype(arr), bool), bool)
371+
check(assert_type(api.is_period_dtype(nparr), bool), bool)
372+
check(assert_type(api.is_period_dtype(dtylike), bool), bool)
373+
check(
374+
assert_type(api.is_period_dtype(dframe), bool),
375+
bool,
376+
)
377+
check(assert_type(api.is_period_dtype(ind), bool), bool)
378+
check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool)
374379

375380

376381
def test_is_re() -> None:
@@ -416,9 +421,14 @@ def test_is_signed_integer_dtype() -> None:
416421

417422

418423
def test_is_sparse() -> None:
419-
check(assert_type(api.is_sparse(arr), bool), bool)
420-
check(assert_type(api.is_sparse(nparr), bool), bool)
421-
check(assert_type(api.is_sparse(dframe), bool), bool)
424+
with pytest_warns_bounded(
425+
FutureWarning,
426+
match="is_sparse is deprecated and will be removed in a future version",
427+
lower="2.0.99",
428+
):
429+
check(assert_type(api.is_sparse(arr), bool), bool)
430+
check(assert_type(api.is_sparse(nparr), bool), bool)
431+
check(assert_type(api.is_sparse(dframe), bool), bool)
422432

423433

424434
def test_is_string_dtype() -> None:

tests/test_frame.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,17 +1098,22 @@ def test_to_markdown() -> None:
10981098
def test_types_to_feather() -> None:
10991099
pytest.importorskip("pyarrow")
11001100
df = pd.DataFrame(data={"col1": [1, 1, 2], "col2": [3, 4, 5]})
1101-
with ensure_clean() as path:
1102-
df.to_feather(path)
1103-
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
1104-
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)
1101+
with pytest_warns_bounded(
1102+
FutureWarning,
1103+
match="is_sparse is deprecated and will be removed in a future version",
1104+
lower="2.0.99",
1105+
):
1106+
with ensure_clean() as path:
1107+
df.to_feather(path)
1108+
# kwargs for pyarrow.feather.write_feather added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
1109+
df.to_feather(path, compression="zstd", compression_level=3, chunksize=2)
11051110

1106-
# to_feather has been able to accept a buffer since pandas 1.0.0
1107-
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
1108-
# Docstring and type were updated in 1.2.0.
1109-
# https://github.com/pandas-dev/pandas/pull/35408
1110-
with open(path, mode="wb") as file:
1111-
df.to_feather(file)
1111+
# to_feather has been able to accept a buffer since pandas 1.0.0
1112+
# See https://pandas.pydata.org/docs/whatsnew/v1.0.0.html
1113+
# Docstring and type were updated in 1.2.0.
1114+
# https://github.com/pandas-dev/pandas/pull/35408
1115+
with open(path, mode="wb") as file:
1116+
df.to_feather(file)
11121117

11131118

11141119
# compare() method added in 1.1.0 https://pandas.pydata.org/docs/whatsnew/v1.1.0.html
@@ -1339,9 +1344,14 @@ def test_types_to_parquet() -> None:
13391344
allows_duplicate_labels=False
13401345
)
13411346
with ensure_clean() as path:
1342-
df.to_parquet(Path(path))
1343-
# to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
1344-
b: bytes = df.to_parquet()
1347+
with pytest_warns_bounded(
1348+
FutureWarning,
1349+
match="is_sparse is deprecated and will be removed in a future version",
1350+
lower="2.0.99",
1351+
):
1352+
df.to_parquet(Path(path))
1353+
# to_parquet() returns bytes when no path given since 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html
1354+
b: bytes = df.to_parquet()
13451355

13461356

13471357
def test_types_to_latex() -> None:

tests/test_io.py

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
from pandas.io.sas.sas_xport import XportReader
7070
from pandas.io.stata import StataReader
7171

72-
from . import lxml_skip
72+
from . import (
73+
lxml_skip,
74+
pytest_warns_bounded,
75+
)
7376

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

8492

8593
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
8694
def test_orc_path():
8795
with ensure_clean() as path:
8896
pathlib_path = Path(path)
89-
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
97+
with pytest_warns_bounded(
98+
FutureWarning,
99+
match="is_sparse is deprecated and will be removed in a future version",
100+
lower="2.0.99",
101+
):
102+
check(assert_type(DF.to_orc(pathlib_path), None), type(None))
90103
check(assert_type(read_orc(pathlib_path), DataFrame), DataFrame)
91104

92105

93106
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
94107
def test_orc_buffer():
95108
with ensure_clean() as path:
96109
file_w = open(path, "wb")
97-
check(assert_type(DF.to_orc(file_w), None), type(None))
110+
with pytest_warns_bounded(
111+
FutureWarning,
112+
match="is_sparse is deprecated and will be removed in a future version",
113+
lower="2.0.99",
114+
):
115+
check(assert_type(DF.to_orc(file_w), None), type(None))
98116
file_w.close()
99117

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

111134

112135
@pytest.mark.skipif(WINDOWS, reason="ORC not available on windows")
113136
def test_orc_bytes():
114-
check(assert_type(DF.to_orc(index=False), bytes), bytes)
137+
with pytest_warns_bounded(
138+
FutureWarning,
139+
match="is_sparse is deprecated and will be removed in a future version",
140+
lower="2.0.99",
141+
):
142+
check(assert_type(DF.to_orc(index=False), bytes), bytes)
115143

116144

117145
@lxml_skip
@@ -504,27 +532,47 @@ def test_json_chunk():
504532

505533
def test_parquet():
506534
with ensure_clean() as path:
507-
check(assert_type(DF.to_parquet(path), None), type(None))
535+
with pytest_warns_bounded(
536+
FutureWarning,
537+
match="is_sparse is deprecated and will be removed in a future version",
538+
lower="2.0.99",
539+
):
540+
check(assert_type(DF.to_parquet(path), None), type(None))
541+
check(assert_type(DF.to_parquet(), bytes), bytes)
508542
check(assert_type(read_parquet(path), DataFrame), DataFrame)
509-
check(assert_type(DF.to_parquet(), bytes), bytes)
510543

511544

512545
def test_parquet_options():
513546
with ensure_clean(".parquet") as path:
514-
check(
515-
assert_type(DF.to_parquet(path, compression=None, index=True), None),
516-
type(None),
517-
)
547+
with pytest_warns_bounded(
548+
FutureWarning,
549+
match="is_sparse is deprecated and will be removed in a future version",
550+
lower="2.0.99",
551+
):
552+
check(
553+
assert_type(DF.to_parquet(path, compression=None, index=True), None),
554+
type(None),
555+
)
518556
check(assert_type(read_parquet(path), DataFrame), DataFrame)
519557

520558

521559
def test_feather():
522560
with ensure_clean() as path:
523-
check(assert_type(DF.to_feather(path), None), type(None))
561+
with pytest_warns_bounded(
562+
FutureWarning,
563+
match="is_sparse is deprecated and will be removed in a future version",
564+
lower="2.0.99",
565+
):
566+
check(assert_type(DF.to_feather(path), None), type(None))
524567
check(assert_type(read_feather(path), DataFrame), DataFrame)
525568
check(assert_type(read_feather(path, columns=["a"]), DataFrame), DataFrame)
526569
bio = io.BytesIO()
527-
check(assert_type(DF.to_feather(bio), None), type(None))
570+
with pytest_warns_bounded(
571+
FutureWarning,
572+
match="is_sparse is deprecated and will be removed in a future version",
573+
lower="2.0.00",
574+
):
575+
check(assert_type(DF.to_feather(bio), None), type(None))
528576
bio.seek(0)
529577
check(assert_type(read_feather(bio), DataFrame), DataFrame)
530578

@@ -1322,13 +1370,22 @@ def test_all_read_without_lxml_dtype_backend() -> None:
13221370
con.close()
13231371

13241372
if not WINDOWS:
1325-
check(assert_type(DF.to_orc(path), None), type(None))
1373+
with pytest_warns_bounded(
1374+
FutureWarning,
1375+
match="is_sparse is deprecated and will be removed in a future version",
1376+
lower="2.0.99",
1377+
):
1378+
check(assert_type(DF.to_orc(path), None), type(None))
13261379
check(
13271380
assert_type(read_orc(path, dtype_backend="numpy_nullable"), DataFrame),
13281381
DataFrame,
13291382
)
1330-
1331-
check(assert_type(DF.to_feather(path), None), type(None))
1383+
with pytest_warns_bounded(
1384+
FutureWarning,
1385+
match="is_sparse is deprecated and will be removed in a future version",
1386+
lower="2.0.99",
1387+
):
1388+
check(assert_type(DF.to_feather(path), None), type(None))
13321389
check(
13331390
assert_type(read_feather(path, dtype_backend="pyarrow"), DataFrame),
13341391
DataFrame,

0 commit comments

Comments
 (0)