Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optypean dtype-like type-aliases #304

Open
jorenham opened this issue Mar 12, 2025 · 0 comments
Open

optypean dtype-like type-aliases #304

jorenham opened this issue Mar 12, 2025 · 0 comments
Assignees
Labels

Comments

@jorenham
Copy link
Member

jorenham commented Mar 12, 2025

This effectively comes down to porting over the optype.numpy.Any*DType type aliases (docs), and stripping away the compatibility stuff for older numpy version.

naming scheme

The naming scheme of these dtype-likes in optype.numpy is admittedly rather awkward, so a that should also be changed (but not in optype; that'd break scipy-stubs).
Some options for a new naming scheme are (taking dtype[int8] and dtype[str_] as example)

  • As{}DType (pros: np.dtypes compat, cons: no abbrev & meh readability)
    • AsInt8DType
    • AsStrDType
  • AsDType{} (pros: autocompletion & could abbr, cons: yoda & np.dtypes incompat)
    • AsDTypeInt8 / AsDType_int8 / AsDType_i1
    • AsDTypeStr / AsDType_str / AsDType_U
  • DTypeLike{} (pros: autocompletion & could abbr & np._typing compat, cons: long & yoda & np.dtypes incompat)
    • DTypeLikeInt8 / DTypeLike_int8 / DTypeLike_i1
    • DTypeLikeStr / DTypeLike_str / DTypeLike_U
  • {}DTypeLike (pros: readability & np.dtypes compat, cons: long & no abbrev)
    • Int8DTypeLike
    • StrDTypeLike

datetime64 and timedelta64

Analogous to the three or four distinct generic variants of the scalar types (unit-based), these dtypes could be further split up into "sub-dtype-likes" for:

  • datetime64[None] / datetime64[int] / datetime64[dt.datetime] / datetime64[dt.date]
  • timedelta64[None] / timedelta64[int] / timedelta64[dt.timedelta]

void

Note that for void things become rather complex, because it includes all possible structured dtypes, but can also be bytes-like. So perhaps it makes sense to split it up into two non-overlapping dtype-like types:

  • structured, i.e. those with .ndim > 0: accepts list[tuple[...]] | ct.Struct | ct.Enum
  • raw, i.e. those with .ndim == 0: accepts type[void] | L["void", "V", "\x14", ...] | ...

incompleteness

Not all dtypes can be completely described, because they accept an infinite amount of possible strings. This is the case for

  • datetime64 and timedelta64 (i.e.e.g. "M8[42as]")
  • flexible, i.e. bytes_, str_, and void (i.e.e.g. "S1337")

So in these cases, a "catch-all" overload for the remaining str should be used.

@jorenham jorenham self-assigned this Mar 12, 2025
@jorenham jorenham changed the title dtype-like aliases à la optype.numpy.Any*DType optypean dtype-like type-aliases Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant