Fix: coerce unknown types to O dtype#10339
Fix: coerce unknown types to O dtype#10339brynpickering wants to merge 17 commits intopydata:mainfrom
Conversation
for more information, see https://pre-commit.ci
|
do you think we could add a quick comment in the code describing what it's doing, for the less informed of us? (does anyone know this better?) |
|
Sure, done. Another options for this would be to check all the args passed to the |
|
@keewis is there any timeline for this to be reviewed? We're currently stuck with xarray v2024.2.0 as a dependency until this is resolved which is starting to cause issues when used in some working environments. |
There was a problem hiding this comment.
sorry, this had completely dropped off my radar.
If this is about scalars, note that you can already wrap your custom object in a 0D array of object dtype to work around this (so you don't have to wait on us)
@shoyer, do you have an opinion on this?
Co-authored-by: Justus Magin <keewis@users.noreply.github.com>
for more information, see https://pre-commit.ci
|
yeah, I thought I'd help you fix the untested parts of what I suggested |
|
@keewis is looks like this one is good to merge. Right? Just needs a note in "what's new" |
|
@jsignell this may have been superseded by #10423? It certainly seems to be at odds with #10423 since a bunch of the extension array tests are now failing. Let me see if removing the implementation here introduced here but keeping the tests (and checking against the MWE I raised in the issue) works as expected. EDIT: the answer to that is no, it doesn't work as expected. The implementation in #10423 means that it won't promote arbitrary python objects to The simplest option would be to use a try/except in |
|
the new tests pass with the code on |
|
@keewis I've removed the two methods previously added in this PR, in favour of the TypeError fallback. I've then removed |
Added a check for Python objects that neither have numpy dtype
dtypeattributes nor are one of the builtin types so that type promotion succeeds and defaults toobjectdtype.This deals with cases where user-defined instances are in the array which would otherwise trip up
numpy.result_type.I did think about placing this in
xarray.core.dtypes.preprocess_typesbut chose to place it closest to where it causes issues (namely, on callingxp.result_type).sumto custom object arrays withmin_count=1if n_dims <= sum_dims #9755whats-new.rstapi.rst