8000 BUG: Use ``__array__`` during dimension discovery · seberg/numpy@48dbe84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 48dbe84

Browse files
committed
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 u 8000 ses 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 numpygh-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 numpygh-13958
1 parent a9bc5db commit 48dbe84

File tree

3 files changed

+187
-170
lines changed

3 files changed

+187
-170
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Converting of empty array-like objects to NumPy arrays
2+
------------------------------------------------------
3+
Objects with ``len(obj) == 0`` which implement an "array-like" interface,
4+
meaning an object implementing ``obj.__array__()``,
5+
``obj.__array_interface__``, ``obj.__array_struct__``, or the python
6+
buffer interface and which are also sequences (i.e. Pandas objects)
7+
will now always retain there shape correctly when converted to an array.
8+
If such an object has a shape of ``(0, 1)`` previously, it could
9+
be converted into an array of of shape ``(0,)`` (losing all dimensions
10+
after the first 0).

0 commit comments

Comments
 (0)
0