Skip to content

Commit 83b7a07

Browse files
committed
implemented LArray.isin
1 parent f26475e commit 83b7a07

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

condarecipe/larray/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ requirements:
2121

2222
run:
2323
- python
24-
- numpy >=1.10
24+
- numpy >=1.13
2525
- pandas >=0.13.1
2626

2727
test:

doc/source/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ Testing/Searching
404404

405405
LArray.equals
406406
LArray.eq
407+
LArray.isin
407408
LArray.nonzero
408409
LArray.all
409410
LArray.all_by

doc/source/changes/version_0_30.rst.inc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@ Backward incompatible changes
1313
New features
1414
------------
1515

16-
* added a feature (see the :ref:`miscellaneous section <misc>` for details).
16+
* added :py:obj:`LArray.isin()` method to check whether each element of an array is contained in a list (or array) of
17+
values.
18+
19+
>>> arr = ndtest((2, 3))
20+
>>> arr
21+
a\b b0 b1 b2
22+
a0 0 1 2
23+
a1 3 4 5
24+
>>> arr.isin([1, 5, 7])
25+
a\b b0 b1 b2
26+
a0 False True False
27+
a1 False False True
28+
>>> arr[arr.isin([1, 5, 7])]
29+
a_b a0_b1 a1_b2
30+
1 5
1731

18-
* added another feature.
32+
* added a feature (see the :ref:`miscellaneous section <misc>` for details).
1933

2034

2135
.. _misc:

larray/core/array.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,6 +5266,48 @@ def general_isnan(a):
52665266
(a1, a2), res_axes = make_numpy_broadcastable([self, other])
52675267
return LArray(np.isclose(a1.data, a2.data, rtol=rtol, atol=atol, equal_nan=nans_equal), res_axes)
52685268

5269+
def isin(self, test_values, assume_unique=False, invert=False):
5270+
r"""
5271+
Computes whether each element of this array is in `test_values`. Returns a boolean array of the same shape as
5272+
this array that is True where the array element is in `test_values` and False otherwise.
5273+
5274+
Parameters
5275+
----------
5276+
test_values : array_like or set
5277+
The values against which to test each element of this array. If `test_values` is not a 1D array, it will be
5278+
converted to one.
5279+
assume_unique : bool, optional
5280+
If True, this array and `test_values` are both assumed to be unique, which can speed up the calculation.
5281+
Defaults to False.
5282+
invert : bool, optional
5283+
If True, the values in the returned array are inverted, as if calculating `element not in test_values`.
5284+
Defaults to False. ``isin(a, b, invert=True)`` is equivalent to (but faster than) ``~isin(a, b)``.
5285+
5286+
Returns
5287+
-------
5288+
LArray
5289+
boolean array of the same shape as this array that is True where the array element is in `test_values`
5290+
and False otherwise.
5291+
5292+
Examples
5293+
--------
5294+
>>> arr = ndtest((2, 3))
5295+
>>> arr
5296+
a\b b0 b1 b2
5297+
a0 0 1 2
5298+
a1 3 4 5
5299+
>>> arr.isin([1, 5, 7])
5300+
a\b b0 b1 b2
5301+
a0 False True False
5302+
a1 False False True
5303+
>>> arr[arr.isin([1, 5, 7])]
5304+
a_b a0_b1 a1_b2
5305+
1 5
5306+
"""
5307+
if isinstance(test_values, set):
5308+
test_values = list(test_values)
5309+
return LArray(np.isin(self.data, test_values, assume_unique=assume_unique, invert=invert), self.axes)
5310+
52695311
def divnot0(self, other):
52705312
"""Divides array by other, but returns 0.0 where other is 0.
52715313

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def readlocal(fname):
1515
DESCRIPTION = "N-D labeled arrays in Python"
1616
LONG_DESCRIPTION = readlocal("README.rst")
1717
SETUP_REQUIRES = []
18-
INSTALL_REQUIRES = ['numpy >= 1.10', 'pandas >= 0.13.1']
18+
INSTALL_REQUIRES = ['numpy >= 1.13', 'pandas >= 0.13.1']
1919
TESTS_REQUIRE = ['pytest', 'pytest-pep8']
2020

2121
LICENSE = 'GPLv3'

0 commit comments

Comments
 (0)