Skip to content
Snippets Groups Projects
Commit 7ba46d49 authored by Bert Palm's avatar Bert Palm 🎇
Browse files

min, max, to_csv, isnull, notnull

parent 5f9f19aa
No related branches found
No related tags found
No related merge requests found
......@@ -191,16 +191,19 @@ class DictOfSeries(_DiosBase):
b int64
dtype: object
"""
if isinstance(attr_or_callable, str):
attr_or_callable = getattr(pd.Series, attr_or_callable)
call = callable(attr_or_callable)
attrOcall = attr_or_callable
if isinstance(attrOcall, str):
attrOcall = getattr(pd.Series, attrOcall)
call = callable(attrOcall)
if not call:
attrOcall = attr_or_callable
data = pd.Series(dtype='O', index=self.columns)
for c in self.columns:
dat = self._data.at[c]
if call:
data.at[c] = attr_or_callable(dat, **kwds)
data.at[c] = attrOcall(dat, **kwds)
else:
data.at[c] = attr_or_callable.fget(dat)
data.at[c] = getattr(dat, attrOcall)
return data
def apply(self, func, axis=0, raw=False, args=(), **kwds):
......@@ -394,6 +397,28 @@ class DictOfSeries(_DiosBase):
def debugDf(self):
return self.to_df()
def min(self, axis=0, skipna=True):
if axis in [0, 'index', None]:
return self.for_each(pd.Series.min, skipna=skipna)
elif axis in [1, 'columns']:
func = lambda s1, s2: s1.where(s1 < s2, s2)
res = self._reduce_horizontal(func, np.inf)
if not skipna:
res.loc[self.isna().any(axis=1)] = np.nan
return res
raise ValueError(axis)
def max(self, axis=None, skipna=None):
if axis in [0, 'index', None]:
return self.for_each(pd.Series.min, skipna=skipna)
elif axis in [1, 'columns']:
func = lambda s1, s2: s1.where(s1 > s2, s2)
res = self._reduce_horizontal(func, -np.inf)
if not skipna:
res.loc[self.isna().any(axis=1)] = np.nan
return res
raise ValueError(axis)
# ----------------------------------------------------------------------
# Boolean stuff
......@@ -432,10 +457,16 @@ class DictOfSeries(_DiosBase):
data = self.for_each('isna')
return DictOfSeries(data=data, itype=self.itype, cast_policy=self._policy, fastpath=True)
def isnull(self):
return self.isna()
def notna(self):
data = self.for_each('notna')
return DictOfSeries(data=data, itype=self.itype, cast_policy=self._policy, fastpath=True)
def notnull(self):
return self.notna()
# ----------------------------------------------------------------------
# Rendering Methods
......@@ -502,6 +533,11 @@ class DictOfSeries(_DiosBase):
return pprint_dios(self, **kwargs)
def to_csv(self, *args, **kwargs):
self.to_df().to_csv(*args, **kwargs)
to_csv.__doc__ = pd.DataFrame.to_csv.__doc__
def _empty_repr(di):
return f"Empty DictOfSeries\n" \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment