Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion databricks/koalas/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ def applymap(self, func):
column_index=[c._internal.column_index[0] for c in applied])
return DataFrame(internal)

# TODO: Series support is not implemented yet.
# TODO: not all arguments are implemented comparing to Pandas' for now.
def aggregate(self, func: Union[List[str], Dict[str, List[str]]]):
"""Aggregate using one or more operations over the specified axis.
Expand Down
2 changes: 0 additions & 2 deletions databricks/koalas/missing/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class _MissingPandasLikeSeries(object):
flags = unsupported_property('flags', deprecated=True)

# Functions
agg = unsupported_function('agg')
aggregate = unsupported_function('aggregate')
align = unsupported_function('align')
argsort = unsupported_function('argsort')
asfreq = unsupported_function('asfreq')
Expand Down
47 changes: 46 additions & 1 deletion databricks/koalas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""
import re
import inspect
from collections import Iterable
from collections import Iterable, OrderedDict
Copy link
Collaborator

@ueshin ueshin Sep 23, 2019

Choose a reason for hiding this comment

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

nit: no need this change anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ueshin right. i just removed it :)

from functools import partial, wraps
from typing import Any, Generic, List, Optional, Tuple, TypeVar, Union

Expand Down Expand Up @@ -2294,6 +2294,51 @@ def apply(self, func, args=(), **kwds):
wrapped = ks.pandas_wraps(return_col=return_sig)(apply_each)
return wrapped(self, *args, **kwds).rename(self.name)

# TODO: not all arguments are implemented comparing to Pandas' for now.
def aggregate(self, func: Union[str, List[str]]):
"""Aggregate using one or more operations over the specified axis.

Parameters
----------
func : str or a list of str
function name(s) as string apply to series.

Returns
-------
scalar, Series
The return can be:
- scalar : when Series.agg is called with single function
- Series : when Series.agg is called with several functions

Notes
-----
`agg` is an alias for `aggregate`. Use the alias.

See Also
--------
databricks.koalas.Series.apply
databricks.koalas.Series.transform

Examples
--------
>>> s = ks.Series([1, 2, 3, 4])
>>> s.agg('min')
1

>>> s.agg(['min', 'max'])
max 4
min 1
Name: 0, dtype: int64
"""
if isinstance(func, list):
return self.to_frame().agg(func)[self.name]
elif isinstance(func, str):
return getattr(self, func)()
else:
raise ValueError("func must be a string or list of strings")

agg = aggregate

def transpose(self, *args, **kwargs):
"""
Return the transpose, which is by definition self.
Expand Down
11 changes: 11 additions & 0 deletions databricks/koalas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,14 @@ def test_astype(self):
kser = koalas.Series(pser)
with self.assertRaisesRegex(ValueError, 'Type int63 not understood'):
kser.astype('int63')

def test_aggregate(self):
pser = pd.Series([10, 20, 15, 30, 45], name='x')
kser = koalas.Series(pser)
msg = 'func must be a string or list of strings'
with self.assertRaisesRegex(ValueError, msg):
kser.aggregate({'x': ['min', 'max']})
msg = ('If the given function is a list, it '
'should only contains function names as strings.')
with self.assertRaisesRegex(ValueError, msg):
kser.aggregate(['min', max])
2 changes: 2 additions & 0 deletions docs/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Function application, GroupBy & Window
:toctree: api/

Series.apply
Series.agg
Series.aggregate
Series.map
Series.groupby
Series.pipe
Expand Down