Skip to content

Commit

Permalink
Indexing methods for Series (Bears-R-Us#2931)
Browse files Browse the repository at this point in the history
* code implementing matching pnadas behavior for series indexing

* missing newline at end of file

* formatting fixes from linter

* fixes for linter, static typing
---
Signed-off-by: Brandon Neth <brandon.neth@hpe.com>

* changes for compatibility with 3.8
---
Signed-off-by: Brandon Neth <brandon.neth@hpe.com>
brandon-neth authored Jan 30, 2024
1 parent eb64c40 commit 0c4835c
Showing 5 changed files with 863 additions and 7 deletions.
42 changes: 41 additions & 1 deletion arkouda/pdarraysetops.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@

Categorical = ForwardRef("Categorical")

__all__ = ["in1d", "concatenate", "union1d", "intersect1d", "setdiff1d", "setxor1d"]
__all__ = ["in1d", "concatenate", "union1d", "intersect1d", "setdiff1d", "setxor1d", "indexof1d"]

logger = getArkoudaLogger(name="pdarraysetops")

@@ -232,6 +232,46 @@ def in1dmulti(a, b, assume_unique=False, symmetric=False):
return in1d(a, b, assume_unique=assume_unique, symmetric=symmetric)


def indexof1d(keys: groupable, arr: groupable) -> Union[pdarray, groupable]:
"""
Returns an integer array of the index values where the values of the first
array appear in the second.
Parameters
----------
keys : pdarray or Strings or Categorical
Input array of values to find the indices of in `arr`.
arr : pdarray or Strings or Categorical
The values to search.
Returns
-------
pdarray, int
The indices of the values of `keys` in `arr`.
Raises
------
TypeError
Raised if either `keys` or `arr` is not a pdarray, Strings, or
Categorical object
RuntimeError
Raised if the dtype of either array is not supported
"""
from arkouda.categorical import Categorical as Categorical_

if isinstance(keys, (pdarray, Strings, Categorical_)):
if isinstance(keys, (Strings, Categorical_)) and not isinstance(arr, (Strings, Categorical_)):
raise TypeError("Arguments must have compatible types, Strings/Categorical")
elif isinstance(keys, pdarray) and not isinstance(arr, pdarray):
raise TypeError("If keys is pdarray, arr must also be pdarray")

repMsg = generic_msg(
cmd="indexof1d",
args={"keys": keys, "arr": arr},
)
return create_pdarray(cast(str, repMsg))


# fmt: off
@typechecked
def concatenate(
Loading
Oops, something went wrong.

0 comments on commit 0c4835c

Please sign in to comment.