-
-
Notifications
You must be signed in to change notification settings - Fork 11k
np.full now defaults to the filling value's dtype. #7437
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder about stupid objects, but I guess we just shouldn't care, anyone who wants to do
np.full(3, (1, 2))
should be prepared to givedtype=object
. (could make itcopy=False
just for the kicks)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well,
np.full(3, (1, 2))
(with or without passingdtype=object
) didn't work and still doesn't work. The real fun happens when someone writenp.full(3, (1, 2, 3))
though (it used to, and still, returnsarray([1, 2, 3])
).Is there a function equivalent to
array(fill_value).dtype
, but that would actually returnobject
when a non-scalar is passed in? I thoughtnp.obj2sctype(..., default=object)
would work, but it returns the dtype of a ndarray when a ndarray is passed in (sonp.full(3, np.array([1, 2, 3]))
would still "fail"). (By the way I findobj2sctype's
"return None if everything fails" somewhat unpythonic.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forget about this, I guess.... object dtype is funny, and you just have to do it manually. Even noticed we had talked about it before, heh. I guess you are right about
obj2sctype
, it might be trying to recreate the corresponding C-function, no idea....There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should we consider that
np.full(3, (1, 2, 3)) ==> np.array([1, 2, 3])
(the old behavior, kept in this patch) is not a stopper? I feel like there should be a way to at least error out there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there should be an error.
arr.fill
kind of tries this, not sure about all the logic it uses.In any case, this is an orthogonal issue, so I think we should ignore it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really, the only reason I didn't merge it yet, was that I liked our special tag, like ENH:, or actually I guess here MAINT: is better, in the commit message ;).