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

added missing basic dict methods

parent 92e23268
No related branches found
No related tags found
No related merge requests found
......@@ -729,6 +729,53 @@ class DictOfSeries:
__or__ = ftools.partialmethod(_op2, op.or_)
__xor__ = ftools.partialmethod(_op2, op.xor)
# dict-like methods
def clear(self):
d = self._data
self._data = pd.Series(dtype=d.dtype, index=type(d.index)([]))
def get(self, key, default=None):
return self._data.get(key, default)
def items(self):
return self._data.items()
def keys(self):
return self.columns
def pop(self, *args):
# We support a default value, like dict, in contrary to pandas.
# Therefore we need to handle args manually, because dict-style pop()
# differ between a single arg and a tuple-arg, with arg and default,
# where the second arg can be anything, including None. If the key is
# not present, and a single arg is given, a KeyError is raised, but
# with a given default value, it is returned instead.
if len(args) == 0:
raise TypeError("pop expected at least 1 arguments, got 0")
if len(args) > 2:
raise TypeError(f"pop expected at most 2 arguments, got {len(args)}")
key, *rest = args
if key in self.columns:
return self._data.pop(key)
elif rest:
return rest.pop()
raise KeyError(key)
def popitem(self):
last = self.columns[-1]
return last, self._data.pop(last)
def setdefault(self, key, default=None):
if key not in self.columns:
self._insert(key, default)
return self._data[key]
def update(self, other):
if not _is_dios_like(other):
other = to_dios(other)
self.aloc[other, ...] = other
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