Skip to content

Conversation

@IngramBJ
Copy link
Owner

@IngramBJ IngramBJ commented Nov 4, 2025

TST: replace ensure_clean with temp_file in pandas/tests/io/formats/test_to_csv.py (xref pandas-dev#62435)

What:
Replace tm.ensure_clean usage with the pytest temp_file fixture (and tmp_path where a specific extension was required) in
pandas/tests/io/formats/test_to_csv.py.

Why:
The project standard is to use the temp_file pytest fixture instead of the legacy ensure_clean helper. This PR is a small, focused change toward the larger effort tracked in issue pandas-dev#62435.

Changes:

  • Replaced usages of ensure_clean / tm.ensure_clean with the pytest temp_file fixture.
  • Where tests required a specific file extension (e.g. .zip, .gz, etc.), used temp_file.with_suffix(...).
  • Where downstream APIs required a string path, used str(path) explicitly to preserve compatibility.
  • No functional test logic changes; only temporary-file helper replacement.

Files changed:

  • pandas/tests/io/formats/test_to_csv.py

Examples of edits:

  • test_to_csv_with_single_column: now accepts temp_file fixture and writes/reads from it directly.
  • compression tests: use temp_file.with_suffix("." + extension) for extension-specific files.
  • binary-handle tests: continue to open the temp_file as before but using the fixture-provided Path.

Local verification:
I ran the modified tests locally and verified the file and individual tests pass:

  • Run the whole file:
    pytest -q pandas/tests/io/formats/test_to_csv.py
    (All tests in the file passed locally.)

  • Run an individual test:
    pytest -q pandas/tests/io/formats/test_to_csv.py::TestToCSV::test_to_csv_with_single_column
    (This test passed locally.)

Pre-commit hooks:

  • Ran pre-commit locally:
    pre-commit run --all-files
    (All configured checks passed.)

Notes:

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TST: Replace ensure_clean utility function with the temp_file pytest fixture

2 participants