diff --git a/dios/dios.py b/dios/dios.py index 7b1b41c2d4cf215548dd4f08fc46c9a599f2781a..954ba13f6acccadd1cc572a2b084a99e4cb5b55d 100644 --- a/dios/dios.py +++ b/dios/dios.py @@ -208,14 +208,13 @@ class DictOfSeries: def _getitem_bool_dios(self, key): # align columns keys = self.columns.intersection(key.columns) - for k in keys: - if not is_bool_indexer(key[k]): - raise ValueError("Must pass DictOfSeries with boolean values only") - new = self.copy_empty(columns=True) + for k in keys: ser = self._data.at[k] boolser = key[k] + if not is_bool_indexer(boolser): + raise ValueError("Must pass DictOfSeries with boolean values only") # align rows idx = boolser[boolser].index.intersection(ser.index) new._data.at[k] = ser.loc[idx] @@ -407,6 +406,19 @@ class DictOfSeries: new = pd.Series(data=new, index=self.columns) return new + @property + def dtypes(self): + s = pd.Series(index=self.columns, dtype='O') + for k in self.columns: + s.at[k] = self._data.at[k].dtype + return s + + def astype(self, dtype, copy=True, errors='raise'): + new = self.copy_empty(columns=False) if copy else self + for k in self.columns.copy(): + new._data.at[k] = self._data.at[k].astype(dtype=dtype, copy=True, errors=errors) + return new + def _op1(self, op): new = self.copy_empty(columns=False) try: diff --git a/dios/locator.py b/dios/locator.py index 2caef26cbc2e5d7b2fbda1dd6f6b95e2e56d6fbd..1d692a06a6c5e7bdd6d06e1e57fd8fc5e5d26f6d 100644 --- a/dios/locator.py +++ b/dios/locator.py @@ -160,11 +160,9 @@ class _aLocIndexer(_Indexer): def __getitem__(self, key): rowkeys, colkeys = self._unpack_key_aloc(key) - new = self._dios.copy_empty(columns=False) for i, c in enumerate(colkeys): new._data.at[c] = self._dios.loc[rowkeys[i], c] - return new def _unpack_key_aloc(self, key): @@ -172,15 +170,22 @@ class _aLocIndexer(_Indexer): Return a list of row indexer and a list of existing(!) column labels. Both list always have the same length and also could be empty together. """ + # boolean dios if is_dios_like(key): colkey = self._dios.columns.intersection(key.columns).to_list() rowkey = [] for c in colkey: - rowkey += [self._data.at[c].index.intersection(key[c].index)] + b = key[c] + if not is_bool_indexer(b): + raise ValueError("Must pass DictOfSeries with boolean values only") + rowkey += [self._data.at[c].index.intersection(b[b].index)] else: rowkey, colkey = self._unpack_key(key) + if is_dios_like(rowkey) or is_dios_like(colkey): + raise ValueError("multidimensional key must be passed as single key") + # make column-slice from scalar if is_hashable(colkey): colkey = [colkey] if colkey in self._dios.columns else []