Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Backports:SLE-15-SP6:Update
python-tables
PyTables-compat-numpy119.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File PyTables-compat-numpy119.patch of Package python-tables
From fdd87f8452a778d451b985dbaa725a4825fa5a25 Mon Sep 17 00:00:00 2001 From: Antonio Valentino <antonio.valentino@tiscali.it> Date: Sat, 26 Sep 2020 22:34:59 +0200 Subject: [PATCH] Improve compatibility with numpy >= 1.19 (closes gh-819) --- tables/flavor.py | 20 +++++++++++++++++++- tables/leaf.py | 6 +++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tables/flavor.py b/tables/flavor.py index 253b06e0e..030578119 100644 --- a/tables/flavor.py +++ b/tables/flavor.py @@ -350,6 +350,24 @@ def _is_python(array): _numpy_desc = "NumPy array, record or scalar" +from numpy.lib import NumpyVersion + + +if NumpyVersion(numpy.__version__) >= NumpyVersion('1.19.0'): + def toarray(array, *args, **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter('error') + try: + array = numpy.array(array, *args, **kwargs) + except numpy.VisibleDeprecationWarning: + raise ValueError( + 'cannot guess the desired dtype from the input') + + return array +else: + toarray = numpy.array + + def _is_numpy(array): return isinstance(array, (numpy.ndarray, numpy.generic)) @@ -390,7 +408,7 @@ def _conv_numpy_to_numpy(array): @_numpy_contiguous def _conv_python_to_numpy(array): - nparr = numpy.array(array) + nparr = toarray(array) if nparr.dtype.kind == 'U': # from Python 3 loads of common strings are disguised as Unicode try: diff --git a/tables/leaf.py b/tables/leaf.py index 05c2ae9a0..e80912c67 100644 --- a/tables/leaf.py +++ b/tables/leaf.py @@ -15,8 +15,8 @@ import numpy -from .flavor import (check_flavor, internal_flavor, - alias_map as flavor_alias_map) +from .flavor import (check_flavor, internal_flavor, toarray, + alias_map as flavor_alias_map) from .node import Node from .filters import Filters from .utils import byteorders, lazyattr, SizeType @@ -539,7 +539,7 @@ def _point_selection(self, key): # Try to convert key to a numpy array. If not possible, # a TypeError will be issued (to be catched later on). try: - key = numpy.array(key) + key = toarray(key) except ValueError: raise TypeError("Invalid index or slice: %r" % (key,)) elif not isinstance(key, numpy.ndarray):
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor