Skip to content

Commit 461e4d4

Browse files
committed
Replace eval to getattr & reuse DataFrame's
1 parent cd7ce09 commit 461e4d4

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

databricks/koalas/series.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,19 +2326,14 @@ def aggregate(self, func: Union[str, List[str]]):
23262326
1
23272327
23282328
>>> s.agg(['min', 'max'])
2329-
min 1
23302329
max 4
2330+
min 1
23312331
Name: 0, dtype: int64
23322332
"""
23332333
if isinstance(func, list):
2334-
if all((isinstance(f, str) for f in func)):
2335-
rows = OrderedDict((f, eval("self.{}()".format(f), dict(self=self))) for f in func)
2336-
return Series(rows)
2337-
else:
2338-
raise ValueError("If the given function is a list, it "
2339-
"should only contains function names as strings.")
2334+
return self.to_frame().agg(func)[self.name]
23402335
elif isinstance(func, str):
2341-
return eval("self.{}()".format(func))
2336+
return getattr(self, func)()
23422337
else:
23432338
raise ValueError("func must be a string or list of strings")
23442339

0 commit comments

Comments
 (0)