Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorder tests in maybe_downcast_numeric (#55825)
* Reorder tests in maybe_downcast_numeric The comment `# if we have any nulls, then we are done` is not consistent with the test `if isna(arr).any()` because `arr` is constructed only from the first element (`r[0]`) not the full ravel'd list of values. Moreover, calling `np.array()` on some random type can have surprising consequences. So instead, do the early-out test as intended, just using `r[0]` without going through `np.array()`. Then test other things about `r[0]`. Only then should we test all the values (and if we have any nulls, then we are done). See #55824 Signed-off-by: Michael Tiemann <[email protected]> * Simplify/optimize tests for downcasting If the first element of `result` is an array, ravel that to get element we will test. Otherwise use it as is. We only need to check whether `result` is all non-null once. Signed-off-by: Michael Tiemann <[email protected]> * Update cast.py Don't use deprecated array indexing on ExtensionArrays. We need to now us `iloc`. Signed-off-by: Michael Tiemann <[email protected]> * Eliminate need to call `ravel` When processing a multidimensional `ndarray`, we can get the first element by calling `result.item(0)` and completely avoid the copying needed by `ravel` to get the first element that way. We can also eliminates an additional conditional check. Signed-off-by: Michael Tiemann <[email protected]> --------- Signed-off-by: Michael Tiemann <[email protected]> Co-authored-by: Richard Shadrach <[email protected]>
- Loading branch information