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

bugfixes

parent 38a9b89f
No related branches found
No related tags found
No related merge requests found
......@@ -241,10 +241,21 @@ class DictOfSeries:
data = self.__getitem__(key)
assert isinstance(data, self.__class__), f"getitem returned data of type {type(data)}"
for k in data.columns:
s = data._data.at[k]
s[:] = value
self._data.at[k].loc[s.index] = s
if is_dios_like(value):
self._setitem_dios(data, value)
else:
for k in data.columns:
s = data._data.at[k]
s[:] = value
self._data.at[k].loc[s.index] = s
def _setitem_dios(self, data, value):
keys = self.columns.intersection(data.columns)
for k in keys:
l = self._data.at[k]
r = value[k]
idx = l.index.intersection(r.index)
l[idx] = r[idx]
@property
def loc(self):
......
......@@ -5,15 +5,6 @@ import contextlib
import operator as op
# @contextlib.contextmanager
# def reraise(prefix="", postfix=""):
# try:
# yield
# except Exception as e:
# raise type(e)(prefix + str(e) + postfix) from e
def get_storage_class_values(cls):
return [getattr(cls, c) for c in cls.__dict__ if not c.startswith("_")]
......
......@@ -16,10 +16,8 @@ class _Indexer:
else:
rowkey, colkey = key, slice(None)
if isinstance(rowkey, tuple):
if isinstance(rowkey, tuple) or isinstance(colkey, tuple):
raise KeyError(f"{key}. tuples are not allowed.")
if is_dios_like(rowkey) or is_dios_like(colkey):
raise ValueError("Cannot index with multidimensional key")
return rowkey, colkey
......@@ -35,7 +33,10 @@ class _LocIndexer(_Indexer):
def __getitem__(self, key):
rowkey, colkey = self._unpack_key(key)
data = self._data.loc[colkey]
if is_dios_like(rowkey) or is_dios_like(colkey):
raise ValueError("Cannot index with multidimensional key")
data = self._data.loc[colkey].copy()
# .loc[any, scalar]
if is_hashable(colkey):
......@@ -56,6 +57,8 @@ class _LocIndexer(_Indexer):
def __setitem__(self, key, value):
rowkey, colkey = self._unpack_key(key)
if is_dios_like(rowkey) or is_dios_like(colkey):
raise ValueError("Cannot index with multidimensional key")
# .loc[any, scalar]
if is_hashable(colkey):
......@@ -81,7 +84,10 @@ class _iLocIndexer(_Indexer):
def __getitem__(self, key):
rowkey, colkey = self._unpack_key(key)
data = self._data.iloc[colkey]
if is_dios_like(rowkey) or is_dios_like(colkey):
raise ValueError("Cannot index with multidimensional key")
data = self._data.iloc[colkey].copy()
# .iloc[any, scalar]
if is_integer(colkey):
......@@ -101,6 +107,9 @@ class _iLocIndexer(_Indexer):
def __setitem__(self, key, value):
rowkey, colkey = self._unpack_key(key)
if is_dios_like(rowkey) or is_dios_like(colkey):
raise ValueError("Cannot index with multidimensional key")
# .iloc[any, scalar]
if is_integer(colkey):
......@@ -116,17 +125,22 @@ class _iLocIndexer(_Indexer):
class _aLocIndexer(_Indexer):
""" align Indexer
automatically align (alignable) values on all possible axis,
and handle indexing with non-existent or missing keys grateful
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def __setitem__(self, key, value):
# fallback to loc
if not is_dios_like(value) and not is_nested_list_like(value):
self._dios.loc[key] = value
# todo
raise NotImplementedError
def __getitem__(self, item):
return item
def __getitem__(self, key):
# todo
raise NotImplementedError
# #############################################################################
......@@ -182,32 +196,3 @@ class _iAtIndexer(_Indexer):
# #############################################################################
def _unpack_value(keys, ix, val):
"""Return a generator that yield (column key, corresponding value, value-align(bool) )
for all columns.
This is analogous to DictOfSeries._unpack_value, but with some modifications."""
# prepare value
val = list(val) if is_iterator(val) else val
val = val.squeeze(axis=1) if is_dios_like(val) else val
dioslike, nlistlike = is_dios_like(val), is_nested_list_like(val)
# check value
if nlistlike and len(val) != len(keys):
raise ValueError(f"could not broadcast input array with length {len(val)}"
f" into dios of length {len(keys)}")
if dioslike:
keys = val.columns.intersection(keys)
for i, k in enumerate(keys):
if dioslike:
yield k, ix, val[k]
elif nlistlike:
yield k, ix, val[i]
else:
yield k, ix, val
def maby_set_series_name(maybe_ser, name):
if isinstance(maybe_ser, pd.Series):
maybe_ser.name = name
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