icecube / event-generator

IceCube event generator
GNU General Public License v3.0
1 stars 2 forks source link

Aliases for builtin data types (int, bool, ...) are deprecated with numpy>= 1.20 #14

Closed fschlueter closed 9 months ago

fschlueter commented 1 year ago

Calling

         if not hasattr(np, self.dtype):
             raise ValueError('Invalid dtype str: {!r}'.format(self.type))

with, e.g., int or bool raises the error. Also see https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

I thought a solution could be something like:

buildin_type_aliases = ["bool", "int", "float", "complex", "object", "str", "long", "unicode"]
replacement_type = ["bool_", "int_", "float_", "complex_", "object_", "str_", "longlong", "unicode_"]

and

        if not isinstance(self.dtype, str):
            raise ValueError('{!r} != {!r}'.format(type(self.dtype), str))

        # replace buildin type with numpy type name
        if self.dtype in buildin_type_aliases:
            self.dtype = replacement_type[buildin_type_aliases.index(self.dtype)]

        if not hasattr(np, self.dtype):
            raise ValueError('Invalid dtype str: {!r}'.format(self.type))

and this seems also to work for me. However, it will not work when hasattr(tf, self.dtype) is executed (this is mentioned in the doc string but I can not find it anywhere in the repo.

mhuen commented 9 months ago

This is now fixed in #17