Skip to content
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

BUG: Compatibility with numpy 1.16.x #178

Closed
pekof opened this issue Feb 27, 2019 · 4 comments
Closed

BUG: Compatibility with numpy 1.16.x #178

pekof opened this issue Feb 27, 2019 · 4 comments

Comments

@pekof
Copy link

pekof commented Feb 27, 2019

comtypes not working with numpy 1.16.x due to PR numpy/numpy#12769

automation.py and safearray.py reference numpy.ctypeslib._typecodes which is removed in that PR

@mobiusklein
Copy link
Contributor

This appears to be solvable in a non-ideal fashion by replacing numpy.ctypeslib._typecodes with numpy.ctypeslib._scalar_type_map.

The optimal solution would be to build the mapping from ctypes type to numpy.dtype using the public API. Something along the lines of:

import numpy as np
from numpy.ctypeslib import as_ctypes_type

ctypes_to_dtypes = {}

for tp in set(np.sctypeDict.values()):
    try:
        ctype_for = as_ctypes_type(tp)
        ctypes_to_dtypes[ctype_for] = tp
    except NotImplementedError:
        continue

This yields:

{ctypes.c_long: numpy.int32,
 ctypes.c_ushort: numpy.uint16,
 ctypes.c_ulonglong: numpy.uint64,
 ctypes.c_longlong: numpy.int64,
 ctypes.c_ubyte: numpy.uint8,
 ctypes.c_byte: numpy.int8,
 ctypes.c_double: numpy.float64,
 ctypes.c_float: numpy.float32,
 ctypes.c_short: numpy.int16,
 ctypes.c_bool: numpy.bool_,
 ctypes.c_ulong: numpy.uint32}

Were there other types supported previously that are missing from this?

@fockez
Copy link

fockez commented Nov 5, 2020

May I ask, when will this fix be merged?

@mobiusklein
Copy link
Contributor

If there are no other types to add support for, I can write a short patch to add this behavior. At the time I posted this solution, I thought that the repository had been abandoned.

@fockez
Copy link

fockez commented Nov 6, 2020

I thought too, but I can still see the new mergers although no new release for a long time.
The other problem is that there is no replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants