Skip to content

Fixes for pandas 2&3#976

Merged
martindurant merged 3 commits into
dask:mainfrom
martindurant:fix
May 6, 2026
Merged

Fixes for pandas 2&3#976
martindurant merged 3 commits into
dask:mainfrom
martindurant:fix

Conversation

@martindurant

Copy link
Copy Markdown
Member

Should work for both pandas 2 (object string by default) and pandas 3 (arrow strings if installed).

@martindurant

Copy link
Copy Markdown
Member Author

@jorisvandenbossche - I didn't mean to come back to it, but I had bot help. Now, fastparquet does support latest pandas again, so the XFAIL(strict) will start to show up as failures. I assume you only test against the released version, so you won't see it until then.

@martindurant martindurant changed the title Fix Fixes for pandas 2&3 May 6, 2026
@martindurant martindurant merged commit a02419a into dask:main May 6, 2026
17 of 18 checks passed
@martindurant martindurant deleted the fix branch May 6, 2026 17:56

@jorisvandenbossche jorisvandenbossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see the update! And sorry for the slow feedback (had some holiday), we are updating the pandas tests now, and noticed one issue

Comment thread fastparquet/api.py
for col, parts in arrow_string_columns.items():
if not parts:
continue
final_arr = _pa.concat_arrays(parts)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
final_arr = _pa.concat_arrays(parts)
final_arr = _pa.chunked_array(parts)

To avoid copying the data, you might want to keep the parts as a chunked array? (concat_arrays will result in an actual contiguous pyarrow.Array)

(pandas uses a chunked array under the hood)

Comment thread fastparquet/api.py
# pre-allocated object array already has None for the missing
# rows; skip the arrow conversion so callers see partial data.
continue
arrow_str = pd.arrays.ArrowStringArray(_pa.chunked_array([final_arr]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this creates the "wrong" extension dtype .. We made it a bit complicated, but the above will create one using the opt-in NA-variant of the string dtype, and not the default NaN-variant (which is the default str dtype in pandas 3), but ArrowStringArray(..) init seems to default to the non-default dtype (I assume for historical reasons).

You could do pd.arrays.ArrowStringArray(_pa.chunked_array([final_arr]), dtype=pd.StringDtype(na_value=np.nan))

But it might be better to use a slightly more general API to construct the series from arrow data:

Suggested change
arrow_str = pd.arrays.ArrowStringArray(_pa.chunked_array([final_arr]))
arrow_str_ser = pd.Series.from_arrow(final_arr)
arrow_str_ser.index = df.index

That should also be more robust in case pandas changes the default str dtype in the future (at least then if something is not correct, it is pandas' responsibility to ensure Series.from_arrow() works correctly).
However, that method requires pandas 3+, and I see that the _USE_ARROW_STRINGS is not sufficient condition for that (since that can also be true with pandas 2, given you are checking the option for that)

(I also only noticed this because of seeing the test assertion in a pandas test)

@jorisvandenbossche

Copy link
Copy Markdown
Member

(I can do a quick PR if you want)

@martindurant

Copy link
Copy Markdown
Member Author

Yes, thanks @jorisvandenbossche , that would be great.

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.

2 participants