Skip to content

DataFrame: Add floating and index Arguments - #1965

Open
ax3l wants to merge 1 commit into
openPMD:devfrom
ax3l:topic-df-floating-index
Open

ax3l wants to merge 1 commit into
openPMD:devfrom
ax3l:topic-df-floating-index

Conversation

@ax3l

@ax3l ax3l commented Nov 4, 2026

Copy link
Copy Markdown
Member

Summary

Two opt-in arguments for the particle dataframe functions. Existing calls behave as before.

  • floating=np.float64 (to_df, to_cudf, to_dask): sets the type of floating-point columns. unit_SI is applied in the wider of the stored and the requested precision, so casting afterwards is not equivalent: it keeps the rounding of a scaling in single precision.
  • index="id" (to_df, to_cudf): uses the particle id as the index and replaces .to_df().set_index("id"). Row-aligned arithmetic between iterations silently compares different particles once their order changes. Series use (iteration, id), which stays unique across iterations.
initial = species_0.to_df(index="id", floating=np.float64)
final = species_100.to_df(index="id", floating=np.float64)
delta_x = final["position_x"] - initial["position_x"]

df = series.to_df("beam", index="id")
df.loc[100]            # same shape as the single-iteration frame
df.xs(42, level="id")  # one particle's trajectory

Notes

  • The default stays the row index. An id default would break .to_df().set_index("id") and df["id"], and id is optional in the standard, so the index type would depend on the file.
  • index="id" raises ValueError if a species has no id record, and warns if ids are not unique, because aligning on duplicates multiplies rows.
  • to_dask has no index=: a per-partition id index gave all-NaN differences once particles changed partition. The docs show .to_dask().set_index("id"), which reads all chunks.

Testing

Adds the first to_df tests (testDataFrame*). Unittest.py and example 11 pass locally with pandas 2.3.3 on Python 3.12 and, with dask 2025.12.0, on Python 3.14.

Not tested: to_cudf has not been run (only checked against the cuDF source), and neither has pandas 3.

🤖 Generated with Claude Code

@ax3l ax3l added bug frontend: Python3 api: new additions to the API labels Nov 4, 2026
@ax3l ax3l added this to the 0.18.0 milestone Nov 4, 2026
@ax3l ax3l removed the bug label Nov 4, 2026
@ax3l
ax3l requested review from franzpoeschel and a balanced review from Copilot November 4, 2026 19:39
@ax3l

ax3l commented Nov 4, 2026

Copy link
Copy Markdown
Member Author

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Scaled integer columns are multiplied in float64 before conversion to the requested wider precision, causing irreversible precision loss for large uint64 values.

1 open issue
What changed in this PR

Adds opt-in floating-point precision and particle-ID indexing to the Python dataframe conversions while preserving default behavior.

Changes:

  • Adds floating to pandas, cuDF, and Dask conversions, with precision-aware SI scaling.
  • Adds index="id" to pandas and cuDF conversions, including iteration-aware indexing and duplicate-ID warnings.
  • Adds conversion tests, usage documentation, and a precision example.
File Description
test/​python/​unittest/​API/​APITest.py Tests defaults, precision conversion, ID indexing, and Dask output.
src/​binding/​python/​openpmd_api/​DataFrame.py Implements precision selection and particle-ID indexing.
src/​binding/​python/​openpmd_api/​DaskDataFrame.py Passes precision selection through delayed chunk reads.
examples/​11_particle_dataframe.py Demonstrates requesting double-precision columns.
docs/​source/​analysis/​rapids.rst Documents cuDF precision and indexing options.
docs/​source/​analysis/​pandas.rst Explains precision control and particle-aligned comparisons.
docs/​source/​analysis/​dask.rst Documents precision control and explicit ID indexing.

Review effort: Balanced

Comment on lines +31 to +32
if floating is not None and np.issubdtype(data.dtype, np.floating):
data = data.astype(np.promote_types(data.dtype, floating), copy=False)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Wow, I thought we already safely deselected ints by filtering by floating point types

Add `floating=` to `to_df`, `to_cudf` and `to_dask`. It sets the type of
floating-point columns and applies `unit_SI` in the wider of the stored
and the requested precision, which casting afterwards cannot do.

Add `index="id"` to `to_df` and `to_cudf` to compare particles by id
instead of by row. Series use `(iteration, id)` as a unique index. The
default index is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ax3l
ax3l force-pushed the topic-df-floating-index branch from 25d5d9d to 6d09e85 Compare November 10, 2026 18:49

@franzpoeschel franzpoeschel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you!

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

api: new additions to the API frontend: Python3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants