Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Conversion from ndpointer to array is broken in 1.15 #12421

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

Closed
eric-wieser opened this issue Nov 19, 2018 · 3 comments
Closed

BUG: Conversion from ndpointer to array is broken in 1.15 #12421

eric-wieser opened this issue Nov 19, 2018 · 3 comments
Labels
00 - Bug 06 - Regression 57 - Close? Issues which may be closable unless discussion continued

Comments

@eric-wieser
Copy link
Member

eric-wieser commented Nov 19, 2018

This code:

import ctypes
import numpy as np

arr = (ctypes.c_double * 6)()
nd_ptr_t = np.ctypeslib.ndpointer(dtype=float, shape=(1, 2, 3))
nd_ptr = ctypes.cast(ctypes.pointer(arr), nd_ptr_t)

np.array(nd_ptr)

Gives

#numpy 1.12
array([[[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]]])
# numpy 1.15
ValueError: '<P' is not a valid PEP 3118 buffer format string
#numpy 1.16-dev
ValueError: Unknown PEP 3118 data type specifier 'P'

The above exception was the direct cause of the following exception:

ValueError: '<P' is not a valid PEP 3118 buffer format string

This is problematic, because it breaks ndpointer._check_retval_, which is needed by toinsson/pyrealsense#82. fixed in #12431

This is an example of the problems predicted in #11150


The new spelling is nd_ptr.contents, which is consistent with how ctypes handles other pointer types.

@eric-wieser eric-wieser changed the title BUG: Conversion from ndpointer to array is broken in 1.16 BUG: Conversion from ndpointer to array is broken in 1.15 Nov 19, 2018
@charris charris added this to the 1.16.0 release milestone Nov 20, 2018
eric-wieser added a commit to eric-wieser/numpy that referenced this issue Nov 21, 2018
This:
* fixes a regression in 1.15, where it became impossible to set the return value of a cdll function to an ndpointer.
* removes ndpointer.__array_interface__, which was being ignored anyway in favor of the PEP3118 buffer protocol
* adds `ndpointer.contents` to recover the lost functionality, while staying in line with the ctypes behavior
* removes another instance of `descr`, which enables overlapping fields to be returned from C functions (such as unions).
* Fixes a long-term bug where using ndpointer as a return type without specifying both type and dtype would produce an object array containing a single `ndpointer`. Now the ndpointer is returned directly.

This relates to numpygh-12421, and likely fixes toinsson/pyrealsense#82
@charris
Copy link
Member

charris commented Nov 22, 2018

Should be closed as won't fix? Going to remove the 1.16 milestone.

@charris charris modified the milestones: 1.16.0 release, 1.17.0 release Nov 22, 2018
@eric-wieser
Copy link
Member Author

Probably needs no milestone - can just leave it open in case anyone has the problem and wants to argue here why we ought to fix it

@bsipocz
Copy link
Member

bsipocz commented Jun 12, 2022

This was said to be a won't fix 3.5 years ago. How about closing it? (Maybe also adding a won't fix label?)

@bsipocz bsipocz added the 57 - Close? Issues which may be closable unless discussion continued label Jun 12, 2022
@mattip mattip closed this as completed Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 06 - Regression 57 - Close? Issues which may be closable unless discussion continued
Projects
None yet
Development

No branches or pull requests

4 participants