Commit ae4cbe0a authored by Ignacio Pickering's avatar Ignacio Pickering Committed by Farhad Ramezanghorbani
Browse files

Change unidiomatic type calls to isinstance and remove deprecated h5py operator (#250)

* Change unidiomatic type calls to isinstance and remove deprecated h5py operator

* Add whitespace after , to make flake8 happy
parent 1c378970
...@@ -22,9 +22,9 @@ class datapacker: ...@@ -22,9 +22,9 @@ class datapacker:
# print(type(v[0])) # print(type(v[0]))
# print(k) # print(k)
if type(v) == list: if isinstance(v, list):
if len(v) != 0: if len(v) != 0:
if type(v[0]) is np.str_ or type(v[0]) is str: if isinstance(v[0], np.str_) or isinstance(v[0], str):
v = [a.encode('utf8') for a in v] v = [a.encode('utf8') for a in v]
g.create_dataset(k, data=v, compression=self.clib, g.create_dataset(k, data=v, compression=self.clib,
...@@ -57,11 +57,11 @@ class anidataloader: ...@@ -57,11 +57,11 @@ class anidataloader:
data = {'path': path} data = {'path': path}
for k in keys: for k in keys:
if not isinstance(item[k], h5py.Group): if not isinstance(item[k], h5py.Group):
dataset = np.array(item[k].value) dataset = np.array(item[k][()])
if type(dataset) is np.ndarray: if isinstance(dataset, np.ndarray):
if dataset.size != 0: if dataset.size != 0:
if type(dataset[0]) is np.bytes_: if isinstance(dataset[0], np.bytes_):
dataset = [a.decode('ascii') dataset = [a.decode('ascii')
for a in dataset] for a in dataset]
...@@ -98,11 +98,11 @@ class anidataloader: ...@@ -98,11 +98,11 @@ class anidataloader:
# print(path) # print(path)
for k in keys: for k in keys:
if not isinstance(item[k], h5py.Group): if not isinstance(item[k], h5py.Group):
dataset = np.array(item[k].value) dataset = np.array(item[k][()])
if type(dataset) is np.ndarray: if isinstance(dataset, np.ndarray):
if dataset.size != 0: if dataset.size != 0:
if type(dataset[0]) is np.bytes_: if isinstance(dataset[0], np.bytes_):
dataset = [a.decode('ascii') for a in dataset] dataset = [a.decode('ascii') for a in dataset]
data.update({k: dataset}) data.update({k: dataset})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment