diff --git a/dios/dios.py b/dios/dios.py index 514ae2866d110c46dd5377d5076fa43df96cb06f..a63ead3790de5ba3acc22d957729c8d47e485cc4 100644 --- a/dios/dios.py +++ b/dios/dios.py @@ -327,10 +327,20 @@ class DictOfSeries: return _iLocIndexer(self) @property - def align(self): + def aloc(self): from dios.locator import _aLocIndexer return _aLocIndexer(self) + @property + def at(self): + from dios.locator import _AtIndexer + return _AtIndexer(self) + + @property + def iat(self): + from dios.locator import _iAtIndexer + return _iAtIndexer(self) + def __str__(self): return self.__repr__() diff --git a/dios/locator.py b/dios/locator.py index 3f3d32e9d11d84c20622021cad696c26b6474160..f0f57fbb4796afbc37acbd51ee96f907c3aede0b 100644 --- a/dios/locator.py +++ b/dios/locator.py @@ -166,6 +166,54 @@ class _aLocIndexer(_Indexer): return item +class _AtIndexer(_Indexer): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def _check_key(self, key): + if not (isinstance(key, tuple) and len(key) == 2 + and is_hashable(key[0]) and is_hashable(key[1])): + raise KeyError(f"{key}. `.at` takes exactly one scalar row-key " + "and one scalar column-key") + + def __getitem__(self, key): + self._check_key(key) + return self._data.at[key[1]].at[key[0]] + + def __setitem__(self, key, value): + self._check_key(key) + if is_dios_like(value) or is_nested_list_like(value): + raise TypeError(".at[] cannot be used to set multi-dimensional values, use .aloc[] instead.") + s = self._data.at[key[1]] + s.at[key[0]] = value + self._data.at[key[1]] = s + + +class _iAtIndexer(_Indexer): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def _check_key(self, key): + if not (isinstance(key, tuple) and len(key) == 2 + and is_integer(key[0]) and is_integer(key[1])): + raise KeyError(f"{key} `.iat` takes exactly one integer positional " + f"row-key and one integer positional scalar column-key") + + def __getitem__(self, key): + self._check_key(key) + return self._data.iat[key[1]].iat[key[0]] + + def __setitem__(self, key, value): + self._check_key(key) + if is_dios_like(value) or is_nested_list_like(value): + raise TypeError(".iat[] cannot be used to set multi-dimensional values, use .aloc[] instead.") + s = self._data.iat[key[1]] + s.iat[key[0]] = value + self._data.iat[key[1]] = s + + def _unpack_value(keys, ix, val): """Return a generator that yield (column key, corresponding value, value-align(bool) ) for all columns.