From 215883330600092452e7ce9258195a266149dbd6 Mon Sep 17 00:00:00 2001 From: Kay-Robert Dormann Date: Fri, 18 Oct 2024 12:12:29 +0200 Subject: [PATCH] added frame.data(list). fixes #35 --- amep/base.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/amep/base.py b/amep/base.py index 4032cc2..d762531 100644 --- a/amep/base.py +++ b/amep/base.py @@ -772,7 +772,7 @@ def keys(self) -> list: return datakeys def data( - self, *args, ptype: int | None = None, zerofill: bool = False, + self, *args: str | list[str], ptype: int | None = None, zerofill: bool = False, return_keys: bool = False) -> tuple[list, np.ndarray]: r''' Returns the entire data frame for all particles or for @@ -788,9 +788,10 @@ def data( Parameters ---------- - *args : str + *args : str | list[str] Parameter keys. One wildcard character asterisk can be used, see - note above. + note above. Either multiple strings or lists of strings are + allowed, a combination should not be used. ptype : int | list, optional Particle type. Is internally converted to a list and all matching ptypes are returned. The default is None. @@ -812,10 +813,21 @@ def data( data = None datakeys = [] + # allow lists of keys as input + islist=False + listresult=[] + for arg in args: + if isinstance(arg, (list, np.ndarray)): + islist=True + listresult.append(self.data(*arg, ptype = ptype, zerofill = zerofill, return_keys = return_keys)) + if islist: + if len(args)==1: + return listresult[0] + return listresult + # return all data if no arguments are given if len(args)==0: args = self.keys - else: # Transform list of all given keys by allowing semi-wildcard matches # One asterisk * is allowed.