Skip to content

Commit 3120d7f

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/binding/python/openpmd_api/DataFrame.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
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, *legacy_args, attributes=None, slice=None):
1414
"""
1515
Load all records of a particle species into a Pandas DataFrame.
1616
1717
Parameters
1818
----------
1919
particle_species : openpmd_api.ParticleSpecies
2020
A ParticleSpecies class in openPMD-api.
21+
legacy_args : tuple
22+
DO NOT USE. Catch-all for legacy, unnamed arguments.
2123
attributes : list of strings, optional
2224
A list of attributes of the particle_species that should be read and
2325
added as extra columns.
@@ -43,6 +45,20 @@ def particles_to_dataframe(particle_species, attributes=None, slice=None):
4345
are optimal arguments for the slice parameter
4446
pandas.DataFrame : the central dataframe object created here
4547
"""
48+
# backwards compatibility: in openPMD-api 0.17+, we added the
49+
# additional "attributes" argument and moved slice= to the end.
50+
if legacy_args:
51+
if attributes is None and slice is None and len(legacy_args) == 1:
52+
slice = legacy_args[0]
53+
import warnings
54+
warnings.warn("The to_df() argument order changed in "
55+
"openPMD-api 0.17.0!\n"
56+
"The slice= argument must be passed as a named argument.",
57+
DeprecationWarning
58+
)
59+
else:
60+
raise RuntimeError("to_df() does not support unnamed arguments!")
61+
4662
# import pandas here for a lazy import
4763
try:
4864
import pandas as pd

0 commit comments

Comments
 (0)