diff --git a/Readme.md b/Readme.md index 343f061e399ddc6e10da0dedbe04ec5a543e9ce0..e8078b6c2a6077e7be353bcc63a20ff476326897 100644 --- a/Readme.md +++ b/Readme.md @@ -136,17 +136,19 @@ are treated similar, as they would passed to `.loc` (actually they are really pa the column, otherwise nothing is selected. [1] - *pd.Series* : align the index from the given Series with the column, what means only common indices are used. The actual values of the series are ignored(!). +- *boolean pd.Series* : like *pd.Series* but only True values are evaluated. + False values are equivalent to missing indices. To treat a boolean series as a *normal* indexer series, as decribed + above, one can use `.aloc(usebool=False)[boolean pd.Series]`. + *special **2D**-indexer* are : - `.aloc[boolean dios-like]` : work same like `di[boolean dios-like]` (see there). - Brief: full align, select where the index is present and the value is True. -- `.aloc[dios-like, ...]` (with Ellipsis) : Align in columns and rows, ignore values. Per common column, - the common indices are selected. The ellipsis forces to ignore the values, so a boolean dios could be given, - where, the values are not taken into account. [2] + Brief: full align, select items, where the index is present and the value is True. +- `.aloc[dios-like, ...]` (with Ellipsis) : Align in columns and rows, ignore its values. Per common column, + the common indices are selected. The ellipsis forces `aloc`, to ignore the values, so a boolean dios could be + treated as a non-boolean. Alternatively `.aloc(usebool=False)[boolean dios-like]` could be used.[2] - `.aloc[nested list-like]` : The inner lists are used as `aloc`-*list*-row-indexer (see there) on all columns. One list for one column, which implies, that the outer list has the same length as the number of columns. -- `.aloc(booldios=True)[boolean dios-like]` : alias for `.aloc[boolean dios-like]` -- `.aloc(booldios=False)[dios-like]` : alias for `.aloc[dios-like, ...]` *special handling of 1D-**values*** @@ -215,7 +217,7 @@ Empty DictOfSeries Columns: ['a', 'b'] ->>> d.aloc[d,...] # (equal to use) d.aloc(booldios=False)[d] +>>> d.aloc[d,...] # (equal to use) d.aloc(usebool=False)[d] a | b | ======== | ===== | 0 0.0 | 1 50 | diff --git a/dios/indexer.py b/dios/indexer.py index 3ebf471ab48aa4799e363e871fd1f014ccc51e68..983a1e1d88e054c09f32386424ba365789a566bd 100644 --- a/dios/indexer.py +++ b/dios/indexer.py @@ -256,10 +256,10 @@ class _aLocIndexer(_Indexer): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._use_bool_dios = True + self._usebool = True - def __call__(self, booldios=True): - self._use_bool_dios = booldios + def __call__(self, usebool=True): + self._usebool = usebool return self def __getitem__(self, key): @@ -380,7 +380,7 @@ class _aLocIndexer(_Indexer): # (II) .aloc(booldios=False)[dios] or # (III) .aloc(booldios=True)[dios] elif _is_dios_like(key): - if self._use_bool_dios: + if self._usebool: return keys_from_bool_dios_like(key) else: return keys_from_dios_like(key) @@ -427,7 +427,10 @@ class _aLocIndexer(_Indexer): # row-alignable: pd.Series(), align rows to every series in colkey (columns) if isinstance(rowkey, pd.Series): - rowkey = [self._data.at[c].index.intersection(rowkey.index) for c in colkey] + if _is_bool_indexer(rowkey) and self._usebool: + rowkey = [self._data.at[c].index.intersection(rowkey[rowkey].index) for c in colkey] + else: + rowkey = [self._data.at[c].index.intersection(rowkey.index) for c in colkey] # handle gracefully: scalar, transform to row-slice elif _is_hashable(rowkey):