Skip to content

TST: cover Dask dataframe string conversion modes - #11936

Open
daa46 wants to merge 1 commit into
pydata:mainfrom
daa46:fix-8092-dask-string-tests
Open

daa46 wants to merge 1 commit into
pydata:mainfrom
daa46:fix-8092-dask-string-tests

Conversation

@daa46

@daa46 daa46 commented Nov 24, 2026

Copy link
Copy Markdown

Description

#8092 tracks two Dataset.to_dask_dataframe() tests that fail when Dask converts string data to PyArrow-backed pandas strings. That conversion is intended Dask behaviour, not a bug in Xarray's production code. The tests were written on the assumption that strings are always object-backed, so their expected DataFrames no longer matched what Dask validly returns.

This PR corrects the tests and removes the obsolete xfails. Both tests are now parametrized over Dask's dataframe.convert-string configuration:

dataframe.convert-string Expected string dtype
Disabled exactly object
Enabled exactly string[pyarrow]

The two tests exercise slightly different paths: one covers a string column when a 2D dataset is flattened, while the other covers a string coordinate used as the DataFrame index. In both cases, I construct the expected DataFrame explicitly and keep the assert_frame_equal checks strict, including the string and numeric dtypes.

I also use raise_if_dask_computes() to make sure creating the DataFrame stays lazy. The Dask configuration is applied within a context manager so it is restored after each test, and the PyArrow-specific case uses Xarray's existing requires_pyarrow marker.

No production code, API, documentation or user-visible behaviour is changed.

Validation: the four parametrized cases passed under pandas 2.3.3 and pandas 3.1.1. Validation also included the related conversion tests (9 passed, 1 unrelated xfail) and a full test_dask.py run (222 passed, 6 skipped, 1 unrelated xfail). Ruff and pre-commit passed on the final patch.

Checklist

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Codex

Prompt summary: I asked Codex to investigate the two Dataset.to_dask_dataframe() test failures reported in #8092 and determine whether they indicated a production bug or outdated test expectations. The requested change was limited to xarray/tests/test_dask.py and needed to remain minimal and test-only.

I asked it to remove the obsolete xfails, cover Dask string conversion with dataframe.convert-string both enabled and disabled, and construct the expected DataFrames independently. The assertions needed to check the exact object-backed and PyArrow-backed string dtypes without using check_dtype=False, while continuing to verify numeric dtypes, index values, names and ordering. I also asked it to confirm that conversion remained lazy, that temporary Dask configuration did not leak between tests, and that the existing unrelated MultiIndex xfail was unchanged.

The validation requested included reproducing the original failures, testing the corrected cases with supported pandas 2.x and 3.x versions, running the related conversion tests and full Dask test module, and running Ruff and pre-commit. I subsequently asked Codex to perform a maintainer-level final review, verify that no competing fix had appeared, commit the reviewed patch with AI co-authorship attribution, and push only the contribution branch to my fork.

Co-authored-by: Codex <noreply@openai.com>
@welcome

welcome Bot commented Nov 24, 2026

Copy link
Copy Markdown

Thank you for opening this pull request! It may take us a few days to respond here, so thank you for being patient.
If you have questions, some answers may be found in our contributing guidelines.

@daa46

daa46 commented Nov 24, 2026

Copy link
Copy Markdown
Author

A note on CI: the two failing tests are Iris conversion tests and aren't related to this PR.

The failing job resolved Iris 3.13.1 alongside python-xxhash 4.1.0. This is a known incompatibility (SciTools/iris#7251), fixed in Iris 3.16.1 by SciTools/iris#7262.

All other executed CI jobs passed, so I have not changed the branch.

This branch has not been deployed

No deployments
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.

xarray/tests/test_dask.py::TestToDaskDataFrame::test_to_dask_dataframe_* test failures when dask+pyarrow are installed

1 participant