Where to put DType classes

NumPy has dtypes (as I am sure everyone knows), but also DType classes. I.e that is the:

import numpy as np
float64_dtype = np.dtype("float64")
type(float64_dtype)

The is the DType class. Besides being referred to in some errors, the classes are not particularly interesting in most code, since we are used to np.dtype("float64"), etc. although StringDType(10) could e.g. be used to do np.dtype("S10").

However, these classes are sensible objects and allow things like isinstance checks. It has also always been a plan to implement abstract DType classes. For example we would have a FloatingDType to represent any floating point number (float16, float32, float64, …), potentially even allowing arr.astype(FloatingDType) (doesn’t actually exist yet).

There is enough use for this, that I would like to finally resolve where to put them and create the names. I have always rejected the main namespace, because it already has the scalar np.int64, etc. and this is just not very common.

So, lets lets try if a poll can help give enough insight here to help make a decision.

What would your preferred place for DType classes be?
  • np.<name>
  • np.types.<name> (might be used for more types)
  • np.dtype_classes.<name>
  • np.lib.types.<name>
  • np.lib.dtype_classes.<name>
  • There must be a better way/place! (please comment)

0 voters

Please don’t hesitate to add a comment!

More options (would prefer no double voting, since this wasn’t multiple choice ;).

What would your preferred place for DType classes be?
  • np.dtypes.<name>
  • np.lib.dtypes.<name>

0 voters

The idea for types came from Python which has types, and it could also be a new home for np.ufunc or maybe the array-function dispatcher (which has no public name).
OTOH, it does make things less discoverable maybe and also might remind users of typing.

why not np.dtypes.<name>? not confusable with typing and shorter than dtype_classes.

1 Like