GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — DEP: Correct dtype in `__array_finalize__` if _set_dtype=None by seberg · Pull Request #31293 · numpy/numpy Conversation
|
|
Hmmmm, or should we even only allow EDIT: So one thing of course is, that if |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| def __array_finalize__(self, obj): | ||
| if self.dtype.type is not record and self.dtype.names is not None: | ||
| if issubclass(self.dtype.type, nt.void) and self.dtype.names is not None: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is the logic used in __setattr__, basically the same I guess, but thought I'd just copy paste it.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
EDIT: Actually, no, I'll just undo this to avoid creating a new dtype here if it isn't necessary. After that dtype.type is always record, so that check should be enough.
Made it to have both checks. The second one is needed for some ridiculous tests to pass, but the original one is definitely OK as a fast-path.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ddec556 to
6895cbc
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This does seem a good path forward! My comments are minimal, mostly about comments, so will approve now.
p.s. I may still follow up with changing the dims & strides beforehand.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * Set ``_set_dtype = None`` in which case ``arr.view(dtype=new_dtype)`` | ||
| will call ``__array_finalize__`` with the new dtype, ensuring that | ||
| any validation ``__array_finalize__`` will run is done. | ||
| * Define ``_set_dtype`` as a function (calling ``ndarray._set_dtype()`` |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
How about, "Of, for a quick fix to avoid DeprecationWarning, define ..."
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * setter): create subclass view first, use the setter, but | ||
| * emit a deprecation asking to implement _set_dtype instead. | ||
| * 3. Otherwise (including plain ndarray): create an ndarray base | ||
| * 3. If _set_dtype is None (or base-class): create an ndarray base |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think "or base-class" is incorrect, otherwise how would one ever get to path 4?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * 3. If _set_dtype is None (or base-class): create an ndarray base | ||
| * view, set dtype internally, then create the subclass view | ||
| * if needed. __array_finalize__ sees the final dtype+shape. | ||
| * 4. Otherwise, call `__array_finalize__` with old dtype and forcibly |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Maybe you meant to write it here, like If _set_dtype is NULL or base-class: ...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * with correct dtype+shape, this will call `__array_finalize__` | ||
| * with the final dtype+shape. | ||
| */ | ||
| if (use_dtype_in_finalize && subtype != &PyArray_Type) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
use_dtype_in_finalize can only be set if it is a subclass, so second part can be omitted.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@seberg - the addition of |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…31293) This avoids using the correct dtype in array_finalize unless _set_dtype = None is set on the class. We also use this new path to make record arrays follow the main class deprecation correctly. This means that recarray does live in the future.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
BUG: a regression from gh-31234 seen in astropy (broadcasting error while creating views of aMasked array)
There was an error while loading. Please reload this page.