|
18 | 18 | import pandas
|
19 | 19 | import pyarrow
|
20 | 20 | import pytest
|
21 |
| -from pandas._testing import ensure_clean |
22 | 21 | from pandas.core.dtypes.common import is_list_like
|
23 | 22 | from pyhdk import __version__ as hdk_version
|
24 | 23 |
|
25 | 24 | from modin.config import StorageFormat
|
26 | 25 | from modin.pandas.test.utils import (
|
27 | 26 | create_test_dfs,
|
28 | 27 | default_to_pandas_ignore_string,
|
| 28 | + get_unique_filename, |
29 | 29 | io_ops_bad_exc,
|
30 | 30 | random_state,
|
31 | 31 | test_data,
|
@@ -324,17 +324,17 @@ def test_read_csv_datetime(
|
324 | 324 |
|
325 | 325 | @pytest.mark.parametrize("engine", [None, "arrow"])
|
326 | 326 | @pytest.mark.parametrize("parse_dates", [None, True, False])
|
327 |
| - def test_read_csv_datetime_tz(self, engine, parse_dates): |
328 |
| - with ensure_clean(".csv") as file: |
329 |
| - with open(file, "w") as f: |
330 |
| - f.write("test\n2023-01-01T00:00:00.000-07:00") |
| 327 | + def test_read_csv_datetime_tz(self, engine, parse_dates, tmp_path): |
| 328 | + unique_filename = get_unique_filename(extension="csv", data_dir=tmp_path) |
| 329 | + with open(unique_filename, "w") as f: |
| 330 | + f.write("test\n2023-01-01T00:00:00.000-07:00") |
331 | 331 |
|
332 |
| - eval_io( |
333 |
| - fn_name="read_csv", |
334 |
| - filepath_or_buffer=file, |
335 |
| - md_extra_kwargs={"engine": engine}, |
336 |
| - parse_dates=parse_dates, |
337 |
| - ) |
| 332 | + eval_io( |
| 333 | + fn_name="read_csv", |
| 334 | + filepath_or_buffer=unique_filename, |
| 335 | + md_extra_kwargs={"engine": engine}, |
| 336 | + parse_dates=parse_dates, |
| 337 | + ) |
338 | 338 |
|
339 | 339 | @pytest.mark.parametrize("engine", [None, "arrow"])
|
340 | 340 | @pytest.mark.parametrize(
|
@@ -382,26 +382,26 @@ def test_read_csv_col_handling(
|
382 | 382 | "c1.1,c1,c1.1,c1,c1.1,c1.2,c1.2,c2",
|
383 | 383 | ],
|
384 | 384 | )
|
385 |
| - def test_read_csv_duplicate_cols(self, cols): |
| 385 | + def test_read_csv_duplicate_cols(self, cols, tmp_path): |
386 | 386 | def test(df, lib, **kwargs):
|
387 | 387 | data = f"{cols}\n"
|
388 |
| - with ensure_clean(".csv") as fname: |
389 |
| - with open(fname, "w") as f: |
390 |
| - f.write(data) |
391 |
| - return lib.read_csv(fname) |
| 388 | + unique_filename = get_unique_filename(extension="csv", data_dir=tmp_path) |
| 389 | + with open(unique_filename, "w") as f: |
| 390 | + f.write(data) |
| 391 | + return lib.read_csv(unique_filename) |
392 | 392 |
|
393 | 393 | run_and_compare(test, data={})
|
394 | 394 |
|
395 |
| - def test_read_csv_dtype_object(self): |
| 395 | + def test_read_csv_dtype_object(self, tmp_path): |
396 | 396 | with pytest.warns(UserWarning) as warns:
|
397 |
| - with ensure_clean(".csv") as file: |
398 |
| - with open(file, "w") as f: |
399 |
| - f.write("test\ntest") |
| 397 | + unique_filename = get_unique_filename(extension="csv", data_dir=tmp_path) |
| 398 | + with open(unique_filename, "w") as f: |
| 399 | + f.write("test\ntest") |
400 | 400 |
|
401 |
| - def test(**kwargs): |
402 |
| - return pd.read_csv(file, dtype={"test": "object"}) |
| 401 | + def test(**kwargs): |
| 402 | + return pd.read_csv(unique_filename, dtype={"test": "object"}) |
403 | 403 |
|
404 |
| - run_and_compare(test, data={}) |
| 404 | + run_and_compare(test, data={}) |
405 | 405 | for warn in warns.list:
|
406 | 406 | assert not re.match(r".*defaulting to pandas.*", str(warn))
|
407 | 407 |
|
@@ -870,30 +870,30 @@ def concat(df1, df2, lib, **kwargs):
|
870 | 870 | @pytest.mark.parametrize("transform", [True, False])
|
871 | 871 | @pytest.mark.parametrize("sort_last", [True, False])
|
872 | 872 | # RecursionError in case of concatenation of big number of frames
|
873 |
| - def test_issue_5889(self, transform, sort_last): |
874 |
| - with ensure_clean(".csv") as file: |
875 |
| - data = {"a": [1, 2, 3], "b": [1, 2, 3]} if transform else {"a": [1, 2, 3]} |
876 |
| - pandas.DataFrame(data).to_csv(file, index=False) |
| 873 | + def test_issue_5889(self, transform, sort_last, tmp_path): |
| 874 | + unique_filename = get_unique_filename(extension="csv", data_dir=tmp_path) |
| 875 | + data = {"a": [1, 2, 3], "b": [1, 2, 3]} if transform else {"a": [1, 2, 3]} |
| 876 | + pandas.DataFrame(data).to_csv(unique_filename, index=False) |
877 | 877 |
|
878 |
| - def test_concat(lib, **kwargs): |
879 |
| - if transform: |
| 878 | + def test_concat(lib, **kwargs): |
| 879 | + if transform: |
880 | 880 |
|
881 |
| - def read_csv(): |
882 |
| - return lib.read_csv(file)["b"] |
| 881 | + def read_csv(): |
| 882 | + return lib.read_csv(unique_filename)["b"] |
883 | 883 |
|
884 |
| - else: |
| 884 | + else: |
885 | 885 |
|
886 |
| - def read_csv(): |
887 |
| - return lib.read_csv(file) |
| 886 | + def read_csv(): |
| 887 | + return lib.read_csv(unique_filename) |
888 | 888 |
|
889 |
| - df = read_csv() |
890 |
| - for _ in range(100): |
891 |
| - df = lib.concat([df, read_csv()]) |
892 |
| - if sort_last: |
893 |
| - df = lib.concat([df, read_csv()], sort=True) |
894 |
| - return df |
| 889 | + df = read_csv() |
| 890 | + for _ in range(100): |
| 891 | + df = lib.concat([df, read_csv()]) |
| 892 | + if sort_last: |
| 893 | + df = lib.concat([df, read_csv()], sort=True) |
| 894 | + return df |
895 | 895 |
|
896 |
| - run_and_compare(test_concat, data={}) |
| 896 | + run_and_compare(test_concat, data={}) |
897 | 897 |
|
898 | 898 |
|
899 | 899 | class TestGroupby:
|
|
0 commit comments