Hi!
Thanks for the great work.
In numpy, any function that receives a dtype can also receive a string representation of that dtype:
import numpy as np
assert np.zeros(3, dtype="float64").dtype == np.zeros(3, dtype=np.float64).dtype
assert np.zeros(3, dtype="float64").dtype != np.zeros(3, dtype=np.float32).dtype
I expected the same behavior in CastTransformer which led to a weird error. The CastTransformer seemed to interpret my string representation of the dtype as a literal string type (i.e., it expected a string as input).
As a fix, we could replace the setting of the dtype in the constructor with an inferred dtype from numpy.
i.e.,
def __init__(self, *, dtype=np.float32):
self.dtype = np.dtype(dtype)
This looks up the appropriate dtype, and is also a no-op if the passed value is already a dtype (and not a string). Alternatively, we could catch whether the passed value is actually a dtype.
def __init__(self, *, dtype=np.float32):
if not _is_dtype(dtype):
raise ValueError("informative message")
self.dtype = dtype
We would have to implement _is_dtype somehow though.
I fully concede that this was user error on my part, but given this is how numpy behaves, maybe the behavior could be copied.
Happy to contribute a PR.
Hi!
Thanks for the great work.
In
numpy, any function that receives a dtype can also receive a string representation of that dtype:I expected the same behavior in
CastTransformerwhich led to a weird error. TheCastTransformerseemed to interpret my string representation of the dtype as a literal string type (i.e., it expected a string as input).As a fix, we could replace the setting of the dtype in the constructor with an inferred dtype from
numpy.i.e.,
This looks up the appropriate dtype, and is also a no-op if the passed value is already a dtype (and not a string). Alternatively, we could catch whether the passed value is actually a dtype.
We would have to implement
_is_dtypesomehow though.I fully concede that this was user error on my part, but given this is how numpy behaves, maybe the behavior could be copied.
Happy to contribute a PR.