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

aloc - boolean series support

parent 01b20e25
No related branches found
No related tags found
No related merge requests found
...@@ -136,17 +136,19 @@ are treated similar, as they would passed to `.loc` (actually they are really pa ...@@ -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] 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 - *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(!). 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 : *special **2D**-indexer* are :
- `.aloc[boolean dios-like]` : work same like `di[boolean dios-like]` (see there). - `.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. 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 values. Per common column, - `.aloc[dios-like, ...]` (with Ellipsis) : Align in columns and rows, ignore its values. Per common column,
the common indices are selected. The ellipsis forces to ignore the values, so a boolean dios could be given, the common indices are selected. The ellipsis forces `aloc`, to ignore the values, so a boolean dios could be
where, the values are not taken into account. [2] 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. - `.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. 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*** *special handling of 1D-**values***
...@@ -215,7 +217,7 @@ Empty DictOfSeries ...@@ -215,7 +217,7 @@ Empty DictOfSeries
Columns: ['a', 'b'] 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 | a | b |
======== | ===== | ======== | ===== |
0 0.0 | 1 50 | 0 0.0 | 1 50 |
......
...@@ -256,10 +256,10 @@ class _aLocIndexer(_Indexer): ...@@ -256,10 +256,10 @@ class _aLocIndexer(_Indexer):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._use_bool_dios = True self._usebool = True
def __call__(self, booldios=True): def __call__(self, usebool=True):
self._use_bool_dios = booldios self._usebool = usebool
return self return self
def __getitem__(self, key): def __getitem__(self, key):
...@@ -380,7 +380,7 @@ class _aLocIndexer(_Indexer): ...@@ -380,7 +380,7 @@ class _aLocIndexer(_Indexer):
# (II) .aloc(booldios=False)[dios] or # (II) .aloc(booldios=False)[dios] or
# (III) .aloc(booldios=True)[dios] # (III) .aloc(booldios=True)[dios]
elif _is_dios_like(key): elif _is_dios_like(key):
if self._use_bool_dios: if self._usebool:
return keys_from_bool_dios_like(key) return keys_from_bool_dios_like(key)
else: else:
return keys_from_dios_like(key) return keys_from_dios_like(key)
...@@ -427,7 +427,10 @@ class _aLocIndexer(_Indexer): ...@@ -427,7 +427,10 @@ class _aLocIndexer(_Indexer):
# row-alignable: pd.Series(), align rows to every series in colkey (columns) # row-alignable: pd.Series(), align rows to every series in colkey (columns)
if isinstance(rowkey, pd.Series): 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 # handle gracefully: scalar, transform to row-slice
elif _is_hashable(rowkey): elif _is_hashable(rowkey):
......
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