-
Notifications
You must be signed in to change notification settings - Fork 51
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
fill_value incompatible with output dtype (stackstac.stack) #260
Comments
Hi, I've also run into this issue. I think this should correctly test if the fill_value will fit into the dtype in both numpy 1.x and 2.x. np.can_cast(np.min_scaler_type(fill_value), dtype) E.g. import numpy as np
np.can_cast(type(0), 'float32') # False
np.can_cast(np.min_scaler_type(0), 'float32') # True Thanks! |
To provide a bit more of related background: The new behaviour of a) ...we want to stick with the guiding principle of "Values must never influence result type" underlying the change in numpy>2, which would implicate that users actually have to specify the fill value as a numpy scalar with a defined dtype (as carried out by @ZZMitch) Regarding b):
|
Hello,
I recently updated to stackstac 0.5.1 and found a bug/incorrect documentation with
stackstac.stack()
and thefill_value
anddtype
parameters. This is related to #250 and tracks back tonumpy.can_cast()
.Take this example, where I want to grab just the fmask band from HLS L30 over an area at the smallest possible dtype ('unit8'):
Example:
The above will fail with:
ValueError: The fill_value 255 is incompatible with the output dtype uint8. Either use dtype='int64', or pick a different fill_value.
Providing another value between 0-255 results in the same error.
Providing a

fill_value
ofnp.uint8(255)
works and creates a stack with the correctdtype
(verified withstack.load()
:Checking
numpy.can_cast()
, which the above error points to, we see:Previously, you could just provide an
int
like 255. So I am not sure if this is a bug or the documentation forstackstac.stack()
needs to be updated to indicate thatfill_value
should specifically be anumpy dtype
.The text was updated successfully, but these errors were encountered: