diff --git a/dios/dios.py b/dios/dios.py index 4b17832db2f9e552d92cb8fb91532b13da090e9e..e4589a5c99d4bdfc4e8274aadefb11bd73ca0d98 100644 --- a/dios/dios.py +++ b/dios/dios.py @@ -123,7 +123,7 @@ class DictOfSeries: @property def columns(self): - return self._data.index + return self._data.index.copy() @columns.setter def columns(self, newindex): @@ -179,7 +179,7 @@ class DictOfSeries: # `s = series([5,6], index=['a','b'])` # s[1] returns 6 instead of raising a KeyError raise KeyError(f"'{key}'") - new = self._data[key] + new = self._data.loc[key] else: keys, ixs, ixalign = self._unpack_key(key) new = self.copy_empty() @@ -188,10 +188,10 @@ class DictOfSeries: return new def _get_item(self, key, ix, ixalign): - ser = self._data[key] + ser = self._data.loc[key] if ixalign: ix = ser.index.intersection(ix.index) - return ser[ix] + return ser.loc[ix] def __setitem__(self, key, value): """ dios[x] = y @@ -232,7 +232,7 @@ class DictOfSeries: if ixalign: ix = ser.index.intersection(ix.index) if isinstance(right, pd.Series): - left = ser[ix] + left = ser.loc[ix] right, ix = align_index_by_policy(left, right) ser.loc[ix] = right @@ -294,14 +294,14 @@ class DictOfSeries: if not isinstance(key, pd.Series): raise ValueError("Must pass Series with boolean values only") keys = self.columns - indexer, ixalign = [key[key]] * len(keys), True + indexer, ixalign = [key.loc[key]] * len(keys), True elif is_dios_like(key): keys = self.columns.intersection(key.columns).to_list() for k in keys: if not is_bool_indexer(key[k]): raise ValueError("Must pass DictOfSeries with boolean values only") - indexer, ixalign = [(key[k])[key[k]] for k in keys], True + indexer, ixalign = [key[k].loc[key[k]] for k in keys], True # slice # ----- # slices always work rows too, but never fail and @@ -438,8 +438,8 @@ class DictOfSeries: def _op1(self, op): new = self.copy_empty() try: - for k in self: - new[k] = op(self._data[k]) + for k in self.columns: + new[k] = op(self._data.loc[k]) except Exception as e: raise type(e)(f"'{OP_MAP[op]} dios' failed: " + str(e)) from e return new @@ -456,23 +456,23 @@ class DictOfSeries: if is_dios_like(other): raiseif(set(other) != set(self), '#keys') for k in self.columns: - left, right = self._data[k], other[k] + left, right = self._data.loc[k], other[k] yield k, op(*doalign(left, right)) elif isinstance(other, pd.Series): for k in self.columns: - left, right = self._data[k], other + left, right = self._data.loc[k], other yield k, op(*doalign(left, right)) elif is_dict_like(other): raiseif(set(other) != set(self), '#keys') for k in self.columns: - yield k, op(self._data[k], other[k]) + yield k, op(self._data.loc[k], other[k]) elif is_nested_list_like(other): raiseif(len(other) != len(self), 'length') for i, k in enumerate(self.columns): - yield k, op(self._data[k], other[i]) + yield k, op(self._data.loc[k], other[i]) elif is_scalar(other) or is_list_like(other): for k in self.columns: - yield k, op(self._data[k], other) + yield k, op(self._data.loc[k], other) else: raise NotImplementedError @@ -539,7 +539,7 @@ class DictOfSeries: # the item from the dict, by our mother class. return self._data[k] else: - return self._data[k].copy() + return self._data.loc[k].copy() for k in self.columns: v = f(getobj(k, inplace), *args, **kwargs) diff --git a/dios/locator.py b/dios/locator.py index 3da7ef91197ae443ed298bb31bf863891911931d..ac7cbdc810bed3d289b3b8e5c90b13c8044afe8c 100644 --- a/dios/locator.py +++ b/dios/locator.py @@ -107,7 +107,7 @@ class _iLocIndexer(_Indexer): def _set_item(self, key, ix, right, ixalign=False): # we do use loc instead of iloc as we get real keys. # this works, because keys keep sorted if they come - # from an index from and series (doesn't work with df) + # from an series-index (doesn't work with df-index) ser = self._data[key] if ixalign: ix = ser.index.intersection(ix.index)