Skip to content

numeric_scalars in type hint disables our typechecking  #2528

Open

Description

@stress-tess

The inclusion of numeric_scalars in the type hint seems to make methods not do any type checking. We should also take a look at similar places where we do type hints with groups that aren't classes and see how we want to handle them

Originally posted by @pierce314159 in #2520 (comment)

Activity

  1. self-assigned this
    on Aug 5, 2024
  2. ajpotts commented on May 23, 2025

    @ajpotts
    Contributor

    I was able to verify that upgrading to typeguard==4.4.2 fixes the problem. To test this, I temporarily altered int_scalars:

    int_scalars = Union[
        int,
        np.int8,
        np.int16,
        np.int32,
        np.int64,
        np.uint8,
        np.uint16,
        # np.uint32,
        np.uint64,
    ]

    And then:

    In [5]: arctan2(np.uint32(2), ak.array([1,2,3]))
    ---------------------------------------------------------------------------
    TypeCheckError                            Traceback (most recent call last)
    Cell In[5], line 1
    ----> 1 arctan2(np.uint32(2), ak.array([1,2,3]))
    
    File ~/git/arkouda/arkouda/numpy/numeric.py:1146, in arctan2(num, denom, where)
       1120     """
       1121     Return the element-wise inverse tangent of the array. The result is between -pi/2 and pi/2.
       1122 
       (...)   1140         Raised if the parameter is not a pdarray
       1141     """
       1142     return _trig_helper(pda, "arctan", where)
       1145 @typechecked
    -> 1146 def arctan2(
       1147     num: Union[pdarray, numeric_scalars],
       1148     denom: Union[pdarray, numeric_scalars],
       1149     where: Union[bool, pdarray] = True,
       1150 ) -> pdarray:
       1151     """
       1152     Return the element-wise inverse tangent of the array pair. The result chosen is the
       1153     signed angle in radians between the ray ending at the origin and passing through the
       (...)   1181         | Raised if where is neither boolean nor a pdarray of boolean
       1182     """
       1183     if not all(isSupportedNumber(arg) or isinstance(arg, pdarray) for arg in [num, denom]):
    
    File ~/anaconda3/envs/arkouda-dev/lib/python3.13/site-packages/typeguard/_functions.py:137, in check_argument_types(func_name, arguments, memo)
        134         raise exc
        136 try:
    --> 137     check_type_internal(value, annotation, memo)
        138 except TypeCheckError as exc:
        139     qualname = qualified_name(value, add_class_prefix=True)
    
    File ~/anaconda3/envs/arkouda-dev/lib/python3.13/site-packages/typeguard/_checkers.py:951, in check_type_internal(value, annotation, memo)
        949     checker = lookup_func(origin_type, args, extras)
        950     if checker:
    --> 951         checker(value, origin_type, args, memo)
        952         return
        954 if isclass(origin_type):
    
    File ~/anaconda3/envs/arkouda-dev/lib/python3.13/site-packages/typeguard/_checkers.py:427, in check_union(value, origin_type, args, memo)
        424 finally:
        425     del errors  # avoid creating ref cycle
    --> 427 raise TypeCheckError(f"did not match any element in the union:\n{formatted_errors}")
    
    TypeCheckError: argument "num" (numpy.uint32) did not match any element in the union:
      arkouda.numpy.pdarrayclass.pdarray: is not an instance of arkouda.numpy.pdarrayclass.pdarray
      float: is neither float or int
      numpy.float64: is not an instance of numpy.float64
      numpy.float32: is not an instance of numpy.float32
      int: is not an instance of int
      numpy.int8: is not an instance of numpy.int8
      numpy.int16: is not an instance of numpy.int16
      numpy.int32: is not an instance of numpy.int32
      numpy.int64: is not an instance of numpy.int64
      numpy.uint8: is not an instance of numpy.uint8
      numpy.uint16: is not an instance of numpy.uint16
      numpy.uint64: is not an instance of numpy.uint64
    
    In [6]: arctan2(np.int32(2), ak.array([1,2,3]))
    Out[6]: array([1.1071487177940904 0.78539816339744828 0.5880026035475675])
    
  3. added a commit that references this issue on May 23, 2025
    ae232f4
  4. added a commit that references this issue on Jun 17, 2025
    951414f
  5. added a commit that references this issue on Jun 27, 2025
    1fafb54
  6. added 11 commits that reference this issue on Aug 5, 2025
    8c1c697
    1aa1721
    2af2e37
    15959b8
    6f8c865
    610a425
    35fc276
    0bfdb0d
    5b15eeb
    2dda20a
    88157f5
  7. added a commit that references this issue on Aug 11, 2025
  8. added a commit that references this issue on Aug 20, 2025
  9. added a commit that references this issue on Sep 15, 2025
    d1abfa5
  10. added 4 commits that reference this issue on Sep 25, 2025
    48c23c8
    a76d019
    ec55ecf
    b4d60f2
  11. added 3 commits that reference this issue on Oct 17, 2025
    cf96627
    43543f5
    c6a2214
  12. removed their assignment
    on Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions