Skip to content

Commit

Permalink
Closes Bears-R-Us#3746 remove ForwardRef (Bears-R-Us#3747)
Browse files Browse the repository at this point in the history
Co-authored-by: Amanda Potts <ajpotts@users.noreply.github.com>
  • Loading branch information
ajpotts and ajpotts committed Sep 4, 2024
1 parent 6de7e3d commit 8f4bd17
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
8 changes: 4 additions & 4 deletions arkouda/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
from typeguard import typechecked

from arkouda.client import generic_msg
from arkouda.numpy.dtypes import bool_ as akbool
from arkouda.numpy.dtypes import dtype as akdtype
from arkouda.numpy.dtypes import int64 as akint64
from arkouda.numpy.dtypes import int_scalars, resolve_scalar_dtype, str_, str_scalars
from arkouda.groupbyclass import GroupBy, unique
from arkouda.infoclass import information
from arkouda.logger import getArkoudaLogger
from arkouda.numeric import cast as akcast
from arkouda.numeric import where
from arkouda.numpy.dtypes import bool_ as akbool
from arkouda.numpy.dtypes import dtype as akdtype
from arkouda.numpy.dtypes import int64 as akint64
from arkouda.numpy.dtypes import int_scalars, resolve_scalar_dtype, str_, str_scalars
from arkouda.pdarrayclass import RegistrationError
from arkouda.pdarrayclass import all as akall
from arkouda.pdarrayclass import create_pdarray, pdarray
Expand Down
14 changes: 10 additions & 4 deletions arkouda/numeric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from enum import Enum
from typing import ForwardRef, List, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, List, Sequence, Tuple, TypeVar, Union
from typing import cast as type_cast
from typing import no_type_check

Expand All @@ -27,8 +27,12 @@
from arkouda.sorting import sort
from arkouda.strings import Strings

Categorical = ForwardRef("Categorical")
SegArray = ForwardRef("SegArray")
if TYPE_CHECKING:
from arkouda.categorical import Categorical
from arkouda.segarray import SegArray
else:
Categorical = TypeVar("Categorical")
SegArray = TypeVar("SegArray")

__all__ = [
"cast",
Expand Down Expand Up @@ -1981,7 +1985,9 @@ def histogramdd(
@typechecked
def value_counts(
pda: pdarray,
) -> Union[Categorical, Tuple[Union[pdarray, Strings], Optional[pdarray]]]: # type: ignore
) -> Tuple[
Union[Union[pdarray, Strings, Categorical], Sequence[Union[pdarray, Strings, Categorical]]], pdarray
]:
"""
Count the occurrences of the unique values of an array.
Expand Down
35 changes: 23 additions & 12 deletions arkouda/pdarraysetops.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
from __future__ import annotations

from typing import ForwardRef, Sequence, Union, cast
from typing import Sequence, TypeVar, Union, cast

import numpy as np
from typeguard import typechecked


from arkouda.client import generic_msg
from arkouda.client_dtypes import BitVector
from arkouda.groupbyclass import GroupBy, groupable, groupable_element_type, unique
from arkouda.logger import getArkoudaLogger
from arkouda.numpy.dtypes import bigint
from arkouda.numpy.dtypes import bool_ as akbool
from arkouda.numpy.dtypes import int64 as akint64
from arkouda.numpy.dtypes import uint64 as akuint64
from arkouda.groupbyclass import GroupBy, groupable, groupable_element_type, unique
from arkouda.logger import getArkoudaLogger
from arkouda.pdarrayclass import create_pdarray, pdarray
from arkouda.pdarraycreation import array, ones, zeros, zeros_like
from arkouda.sorting import argsort
from arkouda.strings import Strings
from typing import TYPE_CHECKING

Categorical = ForwardRef("Categorical")
if TYPE_CHECKING:
from arkouda.categorical import Categorical
else:
Categorical = TypeVar("Categorical")

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

logger = getArkoudaLogger(name="pdarraysetops")


def _in1d_single(
pda1: Union[pdarray, Strings, "Categorical"], # type: ignore
pda2: Union[pdarray, Strings, "Categorical"], # type: ignore
pda1: Union[pdarray, Strings, "Categorical"],
pda2: Union[pdarray, Strings, "Categorical"],
invert: bool = False,
) -> pdarray:
"""
Expand Down Expand Up @@ -131,7 +136,7 @@ def in1d(
assume_unique: bool = False,
symmetric: bool = False,
invert: bool = False,
) -> Union[pdarray, groupable]:
) -> groupable:
"""
Test whether each element of a 1-D array is also present in a second array.
Expand Down Expand Up @@ -176,10 +181,16 @@ def in1d(
raise TypeError("Arguments must have compatible types, Strings/Categorical")
elif isinstance(pda1, pdarray) and not isinstance(pda2, pdarray):
raise TypeError("If pda1 is pdarray, pda2 must also be pda2")
if symmetric:
return _in1d_single(pda1, pda2), _in1d_single(pda2, pda1, invert)
else:
elif isinstance(pda2, (pdarray, Strings, Categorical_)):
if symmetric:
return _in1d_single(pda1, pda2), _in1d_single(pda2, pda1, invert)
return _in1d_single(pda1, pda2, invert)
else:
raise TypeError(
"Inputs should both be Union[pdarray, Strings, Categorical] or both be "
"Sequence[pdarray, Strings, Categorical]."
" (Do not mix and match.)"
)
atypes = np.array([ai.dtype for ai in pda1])
btypes = np.array([bi.dtype for bi in pda2])
if not (atypes == btypes).all():
Expand Down Expand Up @@ -291,9 +302,9 @@ def indexof1d(query: groupable, space: groupable) -> pdarray:
# fmt: off
@typechecked
def concatenate(
arrays: Sequence[Union[pdarray, Strings, "Categorical", ]], # type: ignore
arrays: Sequence[Union[pdarray, Strings, "Categorical", ]],
ordered: bool = True,
) -> Union[pdarray, Strings, "Categorical"]: # type: ignore
) -> Union[pdarray, Strings, Categorical, Sequence[Categorical]]:
"""
Concatenate a list or tuple of ``pdarray`` or ``Strings`` objects into
one ``pdarray`` or ``Strings`` object, respectively.
Expand Down

0 comments on commit 8f4bd17

Please sign in to comment.