Skip to content

Commit c98ba00

Browse files
committed
to_df() backwards compatibility
Specifically for `to_df(np.s[...])` calls that did not name an argument
1 parent b6c4962 commit c98ba00

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/binding/python/openpmd_api/DataFrame.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
import numpy as np
1111

1212

13-
def particles_to_dataframe(particle_species, attributes=None, slice=None):
13+
def particles_to_dataframe(particle_species,
14+
*legacy_args,
15+
attributes=None,
16+
slice=None):
1417
"""
1518
Load all records of a particle species into a Pandas DataFrame.
1619
1720
Parameters
1821
----------
1922
particle_species : openpmd_api.ParticleSpecies
2023
A ParticleSpecies class in openPMD-api.
24+
legacy_args : tuple
25+
DO NOT USE. Catch-all for legacy, unnamed arguments.
2126
attributes : list of strings, optional
2227
A list of attributes of the particle_species that should be read and
2328
added as extra columns.
@@ -43,6 +48,20 @@ def particles_to_dataframe(particle_species, attributes=None, slice=None):
4348
are optimal arguments for the slice parameter
4449
pandas.DataFrame : the central dataframe object created here
4550
"""
51+
# backwards compatibility: in openPMD-api 0.17+, we added the
52+
# additional "attributes" argument and moved slice= to the end.
53+
if legacy_args:
54+
if attributes is None and slice is None and len(legacy_args) == 1:
55+
slice = legacy_args[0]
56+
import warnings
57+
warnings.warn("The to_df() argument order changed in "
58+
"openPMD-api 0.17.0!\nThe slice "
59+
"argument must be passed as a named argument.",
60+
DeprecationWarning
61+
)
62+
else:
63+
raise RuntimeError("to_df() does not support unnamed arguments!")
64+
4665
# import pandas here for a lazy import
4766
try:
4867
import pandas as pd

0 commit comments

Comments
 (0)