8000 BUG: Use ``__array__`` during dimension discovery by seberg · Pull Request #14995 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Use __array__ during dimension discovery #14995

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 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: Use __array__ during dimension discovery
``__array__`` was previously not used during dimension discovery,
while bein gused during dtype discovery (if dtype is not given),
as well as during filling of the resulting array.

This would lead to inconsistencies with respect to array likes
that have a shape including a 0 (typically as first dimension).
Thus a shape of ``(0, 1, 1)`` would be found as ``(0,)`` because
a nested list/sequence cannot represent empty shapes, except 1-D.

This uses the `_array_from_array_like` function, which means that
some coercions may be tiny bit slower, at the gain of removing
a lot of complex code.

(this also reverts commit d0d250a
or the related change).

This is a continuation of work by Sergei Lebedev in gh-13663
which had to be reverted due to problems with Pandas, and the
general inconsistency. This version may not resolve all issues
with pandas, but does resolve the inconsistency.

Closes gh-13958
  • Loading branch information
seberg committed Feb 6, 2020
commit 48dbe8453d6dcbf22e49f0080b364d7f0e642f50
10 changes: 10 additions & 0 deletions doc/release/upcoming_changes/14995.compatibility.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Converting of empty array-like objects to NumPy arrays
------------------------------------------------------
Objects with ``len(obj) == 0`` which implement an "array-like" interface,
meaning an object implementing ``obj.__array__()``,
``obj.__array_interface__``, ``obj.__array_struct__``, or the python
buffer interface and which are also sequences (i.e. Pandas objects)
will now always retain there shape correctly when converted to an array.
If such an object has a shape of ``(0, 1)`` previously, it could
be converted into an array of of shape ``(0,)`` (losing all dimensions
after the first 0).
Loading
0