Skip to content

Commit e3cdd1a

Browse files
authored
Clean up a few Python 2-isms (#586)
* CLN : Use of super modified: zarr/indexing.py modified: zarr/n5.py modified: zarr/storage.py modified: zarr/tests/test_convenience.py * CLN : Remove coding cookies from file utf-8 is the default source code file encoding on python 3 * CLN : Remove u-string prefixes the string prefixes dont do anything on python 3 and are visual noise modified: zarr/tests/test_core.py modified: zarr/tests/test_creation.py modified: zarr/tests/test_filters.py modified: zarr/tests/test_hierarchy.py modified: zarr/util.py * CLN : Remove conditional The conditional always evaluates to True on Python 3 so the rest of the if/elif/else conditional has been removed modified: zarr/storage.py * DOC : Add an entry in release doc modified: docs/release.rst * CLN : Fix a pep8 issue remove the import entirely and use os.replace instead of replace modified: zarr/storage.py
1 parent 0e465a2 commit e3cdd1a

32 files changed

+45
-72
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# zarr documentation build configuration file, created by
54
# sphinx-quickstart on Mon May 2 21:40:09 2016.

docs/release.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Next release
77

88
* `DirectoryStore` now uses `os.scandir`, which should make listing large store
99
faster, :issue:`563`
10+
11+
* Remove a few remaining Python 2-isms.
12+
By :user:`Poruri Sai Rahul <rahulporuri>`; :issue:`393`.
13+
1014
* Fix minor bug in `N5Store`.
1115
By :user:`gsakkis`, :issue:`550`.
1216

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import sys
32

43
from setuptools import setup

zarr/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# flake8: noqa
32
from zarr.codecs import *
43
from zarr.convenience import (consolidate_metadata, copy, copy_all, copy_store,

zarr/attrs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from collections.abc import MutableMapping
32

43
from zarr.meta import parse_metadata

zarr/codecs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# flake8: noqa
32
from numcodecs import *
43
from numcodecs import get_codec, Blosc, Zlib, Delta, AsType, BZ2

zarr/convenience.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Convenience functions for storing and loading data."""
32
import io
43
import itertools

zarr/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import binascii
32
import hashlib
43
import itertools

zarr/creation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from warnings import warn
32

43
import numpy as np

zarr/errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32

43
class MetadataError(Exception):

zarr/hierarchy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
from collections.abc import MutableMapping
32
from itertools import islice
43

zarr/indexing.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import collections
32
import itertools
43
import math
@@ -740,7 +739,7 @@ def __init__(self, selection, array):
740739
selection = np.nonzero(selection[0])
741740

742741
# delegate the rest to superclass
743-
super(MaskIndexer, self).__init__(selection, array)
742+
super().__init__(selection, array)
744743

745744

746745
class VIndex(object):

zarr/meta.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import base64
32
from collections.abc import Mapping
43

zarr/meta_v1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import json
32

43
import numpy as np

zarr/n5.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""This module contains a storage class and codec to support the N5 format.
32
"""
43
import os
@@ -97,7 +96,7 @@ def __getitem__(self, key):
9796

9897
key = invert_chunk_coords(key)
9998

100-
return super(N5Store, self).__getitem__(key)
99+
return super().__getitem__(key)
101100

102101
def __setitem__(self, key, value):
103102

@@ -144,7 +143,7 @@ def __setitem__(self, key, value):
144143

145144
key = invert_chunk_coords(key)
146145

147-
super(N5Store, self).__setitem__(key, value)
146+
super().__setitem__(key, value)
148147

149148
def __delitem__(self, key):
150149

@@ -157,7 +156,7 @@ def __delitem__(self, key):
157156
elif is_chunk_key(key):
158157
key = invert_chunk_coords(key)
159158

160-
super(N5Store, self).__delitem__(key)
159+
super().__delitem__(key)
161160

162161
def __contains__(self, key):
163162

@@ -184,7 +183,7 @@ def __contains__(self, key):
184183

185184
key = invert_chunk_coords(key)
186185

187-
return super(N5Store, self).__contains__(key)
186+
return super().__contains__(key)
188187

189188
def __eq__(self, other):
190189
return (
@@ -200,7 +199,7 @@ def listdir(self, path=None):
200199
# We can't use NestedDirectoryStore's listdir, as it requires
201200
# array_meta_key to be present in array directories, which this store
202201
# doesn't provide.
203-
children = super(NestedDirectoryStore, self).listdir(path=path)
202+
children = super().listdir(path=path)
204203

205204
if self._is_array(path):
206205

@@ -244,7 +243,7 @@ def listdir(self, path=None):
244243

245244
def _load_n5_attrs(self, path):
246245
try:
247-
s = super(N5Store, self).__getitem__(path)
246+
s = super().__getitem__(path)
248247
return json_loads(s)
249248
except KeyError:
250249
return {}

zarr/storage.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""This module contains storage classes for use with Zarr arrays and groups.
32
43
Note that any object implementing the :class:`MutableMapping` interface from the
@@ -29,7 +28,7 @@
2928
import zipfile
3029
from collections import OrderedDict
3130
from collections.abc import MutableMapping
32-
from os import scandir, replace
31+
from os import scandir
3332
from pickle import PicklingError
3433
from threading import Lock, RLock
3534
from typing import Optional, Union, List, Tuple, Dict
@@ -710,7 +709,7 @@ def __init__(self, *args, **kwargs):
710709
"will be removed in the future. Please use MemoryStore.",
711710
DeprecationWarning,
712711
stacklevel=2)
713-
super(DictStore, self).__init__(*args, **kwargs)
712+
super().__init__(*args, **kwargs)
714713

715714

716715
class DirectoryStore(MutableMapping):
@@ -858,7 +857,7 @@ def __setitem__(self, key, value):
858857
self._tofile(value, temp_path)
859858

860859
# move temporary file into place
861-
replace(temp_path, file_path)
860+
os.replace(temp_path, file_path)
862861

863862
finally:
864863
# clean up if temp file still exists for whatever reason
@@ -1139,7 +1138,7 @@ class TempStore(DirectoryStore):
11391138
def __init__(self, suffix='', prefix='zarr', dir=None, normalize_keys=False):
11401139
path = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)
11411140
atexit.register(atexit_rmtree, path)
1142-
super(TempStore, self).__init__(path, normalize_keys=normalize_keys)
1141+
super().__init__(path, normalize_keys=normalize_keys)
11431142

11441143

11451144
_prog_ckey = re.compile(r'^(\d+)(\.\d+)+$')
@@ -1228,23 +1227,23 @@ class NestedDirectoryStore(DirectoryStore):
12281227
"""
12291228

12301229
def __init__(self, path, normalize_keys=False):
1231-
super(NestedDirectoryStore, self).__init__(path, normalize_keys=normalize_keys)
1230+
super().__init__(path, normalize_keys=normalize_keys)
12321231

12331232
def __getitem__(self, key):
12341233
key = _nested_map_ckey(key)
1235-
return super(NestedDirectoryStore, self).__getitem__(key)
1234+
return super().__getitem__(key)
12361235

12371236
def __setitem__(self, key, value):
12381237
key = _nested_map_ckey(key)
1239-
super(NestedDirectoryStore, self).__setitem__(key, value)
1238+
super().__setitem__(key, value)
12401239

12411240
def __delitem__(self, key):
12421241
key = _nested_map_ckey(key)
1243-
super(NestedDirectoryStore, self).__delitem__(key)
1242+
super().__delitem__(key)
12441243

12451244
def __contains__(self, key):
12461245
key = _nested_map_ckey(key)
1247-
return super(NestedDirectoryStore, self).__contains__(key)
1246+
return super().__contains__(key)
12481247

12491248
def __eq__(self, other):
12501249
return (
@@ -1253,7 +1252,7 @@ def __eq__(self, other):
12531252
)
12541253

12551254
def listdir(self, path=None):
1256-
children = super(NestedDirectoryStore, self).listdir(path=path)
1255+
children = super().listdir(path=path)
12571256
if array_meta_key in children:
12581257
# special handling of directories containing an array to map nested chunk
12591258
# keys back to standard chunk keys

zarr/sync.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import os
32
from collections import defaultdict
43
from threading import Lock

zarr/tests/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
# -*- coding: utf-8 -*-

zarr/tests/test_attrs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import json
32
import unittest
43

zarr/tests/test_convenience.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import atexit
32
import os
43
import tempfile
@@ -426,7 +425,7 @@ def check_copied_group(original, copied, without_attrs=False, expect_props=None,
426425
class TestCopy(unittest.TestCase):
427426

428427
def __init__(self, *args, **kwargs):
429-
super(TestCopy, self).__init__(*args, **kwargs)
428+
super().__init__(*args, **kwargs)
430429
self.source_h5py = False
431430
self.dest_h5py = False
432431
self.new_source = group
@@ -715,7 +714,7 @@ def temp_h5f():
715714
class TestCopyHDF5ToZarr(TestCopy):
716715

717716
def __init__(self, *args, **kwargs):
718-
super(TestCopyHDF5ToZarr, self).__init__(*args, **kwargs)
717+
super().__init__(*args, **kwargs)
719718
self.source_h5py = True
720719
self.dest_h5py = False
721720
self.new_source = temp_h5f
@@ -725,7 +724,7 @@ def __init__(self, *args, **kwargs):
725724
class TestCopyZarrToHDF5(TestCopy):
726725

727726
def __init__(self, *args, **kwargs):
728-
super(TestCopyZarrToHDF5, self).__init__(*args, **kwargs)
727+
super().__init__(*args, **kwargs)
729728
self.source_h5py = False
730729
self.dest_h5py = True
731730
self.new_source = group
@@ -735,7 +734,7 @@ def __init__(self, *args, **kwargs):
735734
class TestCopyHDF5ToHDF5(TestCopy):
736735

737736
def __init__(self, *args, **kwargs):
738-
super(TestCopyHDF5ToHDF5, self).__init__(*args, **kwargs)
737+
super().__init__(*args, **kwargs)
739738
self.source_h5py = True
740739
self.dest_h5py = True
741740
self.new_source = temp_h5f

zarr/tests/test_core.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import atexit
32
import os
43
import pickle
@@ -1185,12 +1184,12 @@ def test_object_arrays_vlen_text(self):
11851184
data = np.array(greetings * 1000, dtype=object)
11861185

11871186
z = self.create_array(shape=data.shape, dtype=object, object_codec=VLenUTF8())
1188-
z[0] = u'foo'
1189-
assert z[0] == u'foo'
1190-
z[1] = u'bar'
1191-
assert z[1] == u'bar'
1192-
z[2] = u'baz'
1193-
assert z[2] == u'baz'
1187+
z[0] = 'foo'
1188+
assert z[0] == 'foo'
1189+
z[1] = 'bar'
1190+
assert z[1] == 'bar'
1191+
z[2] = 'baz'
1192+
assert z[2] == 'baz'
11941193
z[:] = data
11951194
a = z[:]
11961195
assert a.dtype == object
@@ -1815,7 +1814,7 @@ def test_attrs_n5_keywords(self):
18151814
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
18161815
for k in n5_keywords:
18171816
with pytest.raises(ValueError):
1818-
z.attrs[k] = u""
1817+
z.attrs[k] = ""
18191818

18201819
def test_compressors(self):
18211820
compressors = [

zarr/tests/test_creation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import atexit
32
import os.path
43
import shutil
@@ -148,7 +147,7 @@ def test_full():
148147
assert np.all(a == v)
149148

150149
# unicode string dtype
151-
v = u'xxx'
150+
v = 'xxx'
152151
z = full(100, chunks=10, fill_value=v, dtype='U3')
153152
assert v == z[0]
154153
a = z[...]

zarr/tests/test_filters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import numpy as np
32
from numcodecs import (BZ2, AsType, Blosc, Categorize, Delta, FixedScaleOffset,
43
PackBits, Quantize, Zlib)
@@ -164,8 +163,8 @@ def test_array_with_packbits_filter():
164163
def test_array_with_categorize_filter():
165164

166165
# setup
167-
data = np.random.choice([u'foo', u'bar', u'baz'], size=100)
168-
flt = Categorize(dtype=data.dtype, labels=[u'foo', u'bar', u'baz'])
166+
data = np.random.choice(['foo', 'bar', 'baz'], size=100)
167+
flt = Categorize(dtype=data.dtype, labels=['foo', 'bar', 'baz'])
169168
filters = [flt]
170169

171170
for compressor in compressors:

zarr/tests/test_hierarchy.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import atexit
32
import os
43
import pickle
@@ -1278,14 +1277,14 @@ def test_tree():
12781277
g5.create_dataset('baz', shape=100, chunks=10)
12791278

12801279
# test root group
1281-
expect_bytes = textwrap.dedent(u"""\
1280+
expect_bytes = textwrap.dedent("""\
12821281
/
12831282
+-- bar
12841283
| +-- baz
12851284
| +-- quux
12861285
| +-- baz (100,) float64
12871286
+-- foo""").encode()
1288-
expect_text = textwrap.dedent(u"""\
1287+
expect_text = textwrap.dedent("""\
12891288
/
12901289
├── bar
12911290
│ ├── baz
@@ -1295,19 +1294,19 @@ def test_tree():
12951294
_check_tree(g1, expect_bytes, expect_text)
12961295

12971296
# test different group
1298-
expect_bytes = textwrap.dedent(u"""\
1297+
expect_bytes = textwrap.dedent("""\
12991298
foo""").encode()
1300-
expect_text = textwrap.dedent(u"""\
1299+
expect_text = textwrap.dedent("""\
13011300
foo""")
13021301
_check_tree(g2, expect_bytes, expect_text)
13031302

13041303
# test different group
1305-
expect_bytes = textwrap.dedent(u"""\
1304+
expect_bytes = textwrap.dedent("""\
13061305
bar
13071306
+-- baz
13081307
+-- quux
13091308
+-- baz (100,) float64""").encode()
1310-
expect_text = textwrap.dedent(u"""\
1309+
expect_text = textwrap.dedent("""\
13111310
bar
13121311
├── baz
13131312
└── quux

zarr/tests/test_indexing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import numpy as np
32
import pytest
43
from numpy.testing import assert_array_equal

zarr/tests/test_info.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import numcodecs
32

43
import zarr

0 commit comments

Comments
 (0)