Skip to content

Clean up a few Python 2-isms #586

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

Merged
merged 6 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# zarr documentation build configuration file, created by
# sphinx-quickstart on Mon May 2 21:40:09 2016.
Expand Down
4 changes: 4 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Next release

* `DirectoryStore` now uses `os.scandir`, which should make listing large store
faster, :issue:`563`

* Remove a few remaining Python 2-isms.
By :user:`Poruri Sai Rahul <rahulporuri>`; :issue:`393`.

* Fix minor bug in `N5Store`.
By :user:`gsakkis`, :issue:`550`.

Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys

from setuptools import setup
Expand Down
1 change: 0 additions & 1 deletion zarr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa
from zarr.codecs import *
from zarr.convenience import (consolidate_metadata, copy, copy_all, copy_store,
Expand Down
1 change: 0 additions & 1 deletion zarr/attrs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from collections.abc import MutableMapping

from zarr.meta import parse_metadata
Expand Down
1 change: 0 additions & 1 deletion zarr/codecs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# flake8: noqa
from numcodecs import *
from numcodecs.registry import codec_registry
1 change: 0 additions & 1 deletion zarr/convenience.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""Convenience functions for storing and loading data."""
import io
import itertools
Expand Down
1 change: 0 additions & 1 deletion zarr/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import binascii
import hashlib
import itertools
Expand Down
1 change: 0 additions & 1 deletion zarr/creation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from warnings import warn

import numpy as np
Expand Down
1 change: 0 additions & 1 deletion zarr/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-


class MetadataError(Exception):
Expand Down
1 change: 0 additions & 1 deletion zarr/hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from collections.abc import MutableMapping
from itertools import islice

Expand Down
3 changes: 1 addition & 2 deletions zarr/indexing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import collections
import itertools
import math
Expand Down Expand Up @@ -740,7 +739,7 @@ def __init__(self, selection, array):
selection = np.nonzero(selection[0])

# delegate the rest to superclass
super(MaskIndexer, self).__init__(selection, array)
super().__init__(selection, array)


class VIndex(object):
Expand Down
1 change: 0 additions & 1 deletion zarr/meta.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import base64
from collections.abc import Mapping

Expand Down
1 change: 0 additions & 1 deletion zarr/meta_v1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import json

import numpy as np
Expand Down
13 changes: 6 additions & 7 deletions zarr/n5.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""This module contains a storage class and codec to support the N5 format.
"""
import os
Expand Down Expand Up @@ -97,7 +96,7 @@ def __getitem__(self, key):

key = invert_chunk_coords(key)

return super(N5Store, self).__getitem__(key)
return super().__getitem__(key)

def __setitem__(self, key, value):

Expand Down Expand Up @@ -144,7 +143,7 @@ def __setitem__(self, key, value):

key = invert_chunk_coords(key)

super(N5Store, self).__setitem__(key, value)
super().__setitem__(key, value)

def __delitem__(self, key):

Expand All @@ -157,7 +156,7 @@ def __delitem__(self, key):
elif is_chunk_key(key):
key = invert_chunk_coords(key)

super(N5Store, self).__delitem__(key)
super().__delitem__(key)

def __contains__(self, key):

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

key = invert_chunk_coords(key)

return super(N5Store, self).__contains__(key)
return super().__contains__(key)

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

if self._is_array(path):

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

def _load_n5_attrs(self, path):
try:
s = super(N5Store, self).__getitem__(path)
s = super().__getitem__(path)
return json_loads(s)
except KeyError:
return {}
Expand Down
21 changes: 10 additions & 11 deletions zarr/storage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""This module contains storage classes for use with Zarr arrays and groups.

Note that any object implementing the :class:`MutableMapping` interface from the
Expand Down Expand Up @@ -29,7 +28,7 @@
import zipfile
from collections import OrderedDict
from collections.abc import MutableMapping
from os import scandir, replace
from os import scandir
from pickle import PicklingError
from threading import Lock, RLock
import uuid
Expand Down Expand Up @@ -669,7 +668,7 @@ def __init__(self, *args, **kwargs):
"will be removed in the future. Please use MemoryStore.",
DeprecationWarning,
stacklevel=2)
super(DictStore, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)


class DirectoryStore(MutableMapping):
Expand Down Expand Up @@ -817,7 +816,7 @@ def __setitem__(self, key, value):
self._tofile(value, temp_path)

# move temporary file into place
replace(temp_path, file_path)
os.replace(temp_path, file_path)

finally:
# clean up if temp file still exists for whatever reason
Expand Down Expand Up @@ -1098,7 +1097,7 @@ class TempStore(DirectoryStore):
def __init__(self, suffix='', prefix='zarr', dir=None, normalize_keys=False):
path = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir)
atexit.register(atexit_rmtree, path)
super(TempStore, self).__init__(path, normalize_keys=normalize_keys)
super().__init__(path, normalize_keys=normalize_keys)


_prog_ckey = re.compile(r'^(\d+)(\.\d+)+$')
Expand Down Expand Up @@ -1187,23 +1186,23 @@ class NestedDirectoryStore(DirectoryStore):
"""

def __init__(self, path, normalize_keys=False):
super(NestedDirectoryStore, self).__init__(path, normalize_keys=normalize_keys)
super().__init__(path, normalize_keys=normalize_keys)

def __getitem__(self, key):
key = _nested_map_ckey(key)
return super(NestedDirectoryStore, self).__getitem__(key)
return super().__getitem__(key)

def __setitem__(self, key, value):
key = _nested_map_ckey(key)
super(NestedDirectoryStore, self).__setitem__(key, value)
super().__setitem__(key, value)

def __delitem__(self, key):
key = _nested_map_ckey(key)
super(NestedDirectoryStore, self).__delitem__(key)
super().__delitem__(key)

def __contains__(self, key):
key = _nested_map_ckey(key)
return super(NestedDirectoryStore, self).__contains__(key)
return super().__contains__(key)

def __eq__(self, other):
return (
Expand All @@ -1212,7 +1211,7 @@ def __eq__(self, other):
)

def listdir(self, path=None):
children = super(NestedDirectoryStore, self).listdir(path=path)
children = super().listdir(path=path)
if array_meta_key in children:
# special handling of directories containing an array to map nested chunk
# keys back to standard chunk keys
Expand Down
1 change: 0 additions & 1 deletion zarr/sync.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import os
from collections import defaultdict
from threading import Lock
Expand Down
1 change: 0 additions & 1 deletion zarr/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 0 additions & 1 deletion zarr/tests/test_attrs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import json
import unittest

Expand Down
9 changes: 4 additions & 5 deletions zarr/tests/test_convenience.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import atexit
import os
import tempfile
Expand Down Expand Up @@ -426,7 +425,7 @@ def check_copied_group(original, copied, without_attrs=False, expect_props=None,
class TestCopy(unittest.TestCase):

def __init__(self, *args, **kwargs):
super(TestCopy, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.source_h5py = False
self.dest_h5py = False
self.new_source = group
Expand Down Expand Up @@ -715,7 +714,7 @@ def temp_h5f():
class TestCopyHDF5ToZarr(TestCopy):

def __init__(self, *args, **kwargs):
super(TestCopyHDF5ToZarr, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.source_h5py = True
self.dest_h5py = False
self.new_source = temp_h5f
Expand All @@ -725,7 +724,7 @@ def __init__(self, *args, **kwargs):
class TestCopyZarrToHDF5(TestCopy):

def __init__(self, *args, **kwargs):
super(TestCopyZarrToHDF5, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.source_h5py = False
self.dest_h5py = True
self.new_source = group
Expand All @@ -735,7 +734,7 @@ def __init__(self, *args, **kwargs):
class TestCopyHDF5ToHDF5(TestCopy):

def __init__(self, *args, **kwargs):
super(TestCopyHDF5ToHDF5, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.source_h5py = True
self.dest_h5py = True
self.new_source = temp_h5f
Expand Down
15 changes: 7 additions & 8 deletions zarr/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import atexit
import os
import pickle
Expand Down Expand Up @@ -1185,12 +1184,12 @@ def test_object_arrays_vlen_text(self):
data = np.array(greetings * 1000, dtype=object)

z = self.create_array(shape=data.shape, dtype=object, object_codec=VLenUTF8())
z[0] = u'foo'
assert z[0] == u'foo'
z[1] = u'bar'
assert z[1] == u'bar'
z[2] = u'baz'
assert z[2] == u'baz'
z[0] = 'foo'
assert z[0] == 'foo'
z[1] = 'bar'
assert z[1] == 'bar'
z[2] = 'baz'
assert z[2] == 'baz'
z[:] = data
a = z[:]
assert a.dtype == object
Expand Down Expand Up @@ -1815,7 +1814,7 @@ def test_attrs_n5_keywords(self):
z = self.create_array(shape=(1050,), chunks=100, dtype='i4')
for k in n5_keywords:
with pytest.raises(ValueError):
z.attrs[k] = u""
z.attrs[k] = ""

def test_compressors(self):
compressors = [
Expand Down
3 changes: 1 addition & 2 deletions zarr/tests/test_creation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import atexit
import os.path
import shutil
Expand Down Expand Up @@ -148,7 +147,7 @@ def test_full():
assert np.all(a == v)

# unicode string dtype
v = u'xxx'
v = 'xxx'
z = full(100, chunks=10, fill_value=v, dtype='U3')
assert v == z[0]
a = z[...]
Expand Down
5 changes: 2 additions & 3 deletions zarr/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import numpy as np
from numcodecs import (BZ2, AsType, Blosc, Categorize, Delta, FixedScaleOffset,
PackBits, Quantize, Zlib)
Expand Down Expand Up @@ -164,8 +163,8 @@ def test_array_with_packbits_filter():
def test_array_with_categorize_filter():

# setup
data = np.random.choice([u'foo', u'bar', u'baz'], size=100)
flt = Categorize(dtype=data.dtype, labels=[u'foo', u'bar', u'baz'])
data = np.random.choice(['foo', 'bar', 'baz'], size=100)
flt = Categorize(dtype=data.dtype, labels=['foo', 'bar', 'baz'])
filters = [flt]

for compressor in compressors:
Expand Down
13 changes: 6 additions & 7 deletions zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import atexit
import os
import pickle
Expand Down Expand Up @@ -1278,14 +1277,14 @@ def test_tree():
g5.create_dataset('baz', shape=100, chunks=10)

# test root group
expect_bytes = textwrap.dedent(u"""\
expect_bytes = textwrap.dedent("""\
/
+-- bar
| +-- baz
| +-- quux
| +-- baz (100,) float64
+-- foo""").encode()
expect_text = textwrap.dedent(u"""\
expect_text = textwrap.dedent("""\
/
├── bar
│ ├── baz
Expand All @@ -1295,19 +1294,19 @@ def test_tree():
_check_tree(g1, expect_bytes, expect_text)

# test different group
expect_bytes = textwrap.dedent(u"""\
expect_bytes = textwrap.dedent("""\
foo""").encode()
expect_text = textwrap.dedent(u"""\
expect_text = textwrap.dedent("""\
foo""")
_check_tree(g2, expect_bytes, expect_text)

# test different group
expect_bytes = textwrap.dedent(u"""\
expect_bytes = textwrap.dedent("""\
bar
+-- baz
+-- quux
+-- baz (100,) float64""").encode()
expect_text = textwrap.dedent(u"""\
expect_text = textwrap.dedent("""\
bar
├── baz
└── quux
Expand Down
1 change: 0 additions & 1 deletion zarr/tests/test_indexing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import numpy as np
import pytest
from numpy.testing import assert_array_equal
Expand Down
1 change: 0 additions & 1 deletion zarr/tests/test_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import numcodecs

import zarr
Expand Down
Loading