Skip to content

Commit

Permalink
refactor: simplify nplike typing
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Nov 28, 2022
1 parent b532fe6 commit e405d32
Show file tree
Hide file tree
Showing 5 changed files with 329 additions and 353 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ ignore_missing_imports = true
[[tool.mypy.overrides]]
module = [
'awkward.contents.*',
'awkward._nplikes.*',
]
ignore_errors = false
ignore_missing_imports = false
20 changes: 11 additions & 9 deletions src/awkward/_nplikes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

import numpy
from numpy import bytes_, datetime64, dtype, intp, longlong, str_, timedelta64
from numpy import dtype

__all__ = [
"bool_",
Expand All @@ -17,17 +17,11 @@
"uint16",
"uint32",
"uint64",
"longlong",
"float32",
"float64",
"complex64",
"complex128",
"str_",
"bytes_",
"intp",
"dtype",
"datetime64",
"timedelta64",
]

# DTypes ###############################################################################################################
Expand Down Expand Up @@ -68,9 +62,9 @@
# (Awkward code can't rely on these beign available)
# we can still allow our code to test for them
if hasattr(numpy, "float16"):
numeric_dtypes = (*numeric_dtypes, dtype(numpy.float16))
numeric_dtypes = (*numeric_dtypes, dtype(numpy.float16)) # type: ignore
if hasattr(numpy, "complex256"):
numeric_dtypes = (*numeric_dtypes, dtype(numpy.complex256))
numeric_dtypes = (*numeric_dtypes, dtype(numpy.complex256)) # type: ignore


def is_datetime(dtype: dtype) -> bool:
Expand All @@ -87,3 +81,11 @@ def is_timelike(dtype: dtype) -> bool:

def is_known_dtype(dtype: dtype) -> bool:
return dtype in all_dtypes or is_timelike(dtype)


def is_string(dtype: dtype) -> bool:
return dtype.type == numpy.string_


def is_bytes(dtype: dtype) -> bool:
return dtype.type == numpy.bytes_
Loading

0 comments on commit e405d32

Please sign in to comment.