ramonhagenaars / nptyping

💡 Type hints for Numpy and Pandas
MIT License
576 stars 29 forks source link

Nested dtype support #81

Closed bbudescu closed 2 years ago

bbudescu commented 2 years ago

How would you be able to use nptyping to define the type of a structured array with the following dtype:

dtype = numpy.dtype([('index', numpy.uint64), ('measurements', numpy.float64, (2,))])

I tried variations of

NDArray[Shape["*"], Structure["index: UInt64, measurements: Float64"]])

but this doesn't work (assert_isinstance fails), and I couldn't define anything in the docs that would allow for specifying the shape (2,) of the measurements sub-array.

Would it be possible to directly use dtype objects for type specs?

ramonhagenaars commented 2 years ago

Hi @bbudescu. This is not yet possible in the current version, but I'm considering to support this in a next release with the following syntax:

Structure["some_name: Float64[<SHAPE-EXPRESSION>], some_other_name: Float64"]

This would allow the same shape expression syntax with all its goodies (variables, labels, etc.) for the subarrays.

Would it be possible to directly use dtype objects for type specs?

That's a good idea I think to allow that next to Structure, it makes sense.