Skip to content

Commit d330cdf

Browse files
jrbourbeaualimanfoo
authored andcommitted
Rename DictStore to MemoryStore (#455)
* Renames DictStore to MemoryStore * Adds DictStore aliasing with deprecation warning * Adds item to release notes
1 parent c4d7f49 commit d330cdf

File tree

9 files changed

+49
-21
lines changed

9 files changed

+49
-21
lines changed

docs/api/storage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Storage (``zarr.storage``)
22
==========================
33
.. automodule:: zarr.storage
44

5-
.. autoclass:: DictStore
5+
.. autoclass:: MemoryStore
66
.. autoclass:: DirectoryStore
77
.. autoclass:: TempStore
88
.. autoclass:: NestedDirectoryStore

docs/release.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Release notes
22
=============
33

4+
Upcoming Release
5+
----------------
6+
7+
* Rename ``DictStore`` to ``MemoryStore``.
8+
By :user:`James Bourbeau <jrbourbeau>`; :issue:`455`
9+
10+
411
.. _release_2.3.2:
512

613
2.3.2

docs/tutorial.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ property. E.g.::
367367
Name : /
368368
Type : zarr.hierarchy.Group
369369
Read-only : False
370-
Store type : zarr.storage.DictStore
370+
Store type : zarr.storage.MemoryStore
371371
No. members : 1
372372
No. arrays : 0
373373
No. groups : 1
@@ -377,7 +377,7 @@ property. E.g.::
377377
Name : /foo
378378
Type : zarr.hierarchy.Group
379379
Read-only : False
380-
Store type : zarr.storage.DictStore
380+
Store type : zarr.storage.MemoryStore
381381
No. members : 2
382382
No. arrays : 2
383383
No. groups : 0
@@ -392,7 +392,7 @@ property. E.g.::
392392
Order : C
393393
Read-only : False
394394
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
395-
Store type : zarr.storage.DictStore
395+
Store type : zarr.storage.MemoryStore
396396
No. bytes : 8000000 (7.6M)
397397
No. bytes stored : 33240 (32.5K)
398398
Storage ratio : 240.7
@@ -407,7 +407,7 @@ property. E.g.::
407407
Order : C
408408
Read-only : False
409409
Compressor : Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0)
410-
Store type : zarr.storage.DictStore
410+
Store type : zarr.storage.MemoryStore
411411
No. bytes : 4000000 (3.8M)
412412
No. bytes stored : 23943 (23.4K)
413413
Storage ratio : 167.1
@@ -1333,7 +1333,7 @@ module can be pickled, as can the built-in ``dict`` class which can also be used
13331333
storage.
13341334

13351335
Note that if an array or group is backed by an in-memory store like a ``dict`` or
1336-
:class:`zarr.storage.DictStore`, then when it is pickled all of the store data will be
1336+
:class:`zarr.storage.MemoryStore`, then when it is pickled all of the store data will be
13371337
included in the pickled data. However, if an array or group is backed by a persistent
13381338
store like a :class:`zarr.storage.DirectoryStore`, :class:`zarr.storage.ZipStore` or
13391339
:class:`zarr.storage.DBMStore` then the store data **are not** pickled. The only thing

zarr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from zarr.core import Array
77
from zarr.creation import (empty, zeros, ones, full, array, empty_like, zeros_like,
88
ones_like, full_like, open_array, open_like, create)
9-
from zarr.storage import (DictStore, DirectoryStore, ZipStore, TempStore,
9+
from zarr.storage import (DictStore, MemoryStore, DirectoryStore, ZipStore, TempStore,
1010
NestedDirectoryStore, DBMStore, LMDBStore, SQLiteStore,
1111
LRUStoreCache, ABSStore, RedisStore, MongoDBStore)
1212
from zarr.hierarchy import group, open_group, Group

zarr/hierarchy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from zarr.attrs import Attributes
1010
from zarr.core import Array
1111
from zarr.storage import (contains_array, contains_group, init_group,
12-
DictStore, group_meta_key, attrs_key, listdir, rename, rmdir)
12+
MemoryStore, group_meta_key, attrs_key, listdir, rename, rmdir)
1313
from zarr.creation import (array, create, empty, zeros, ones, full,
1414
empty_like, zeros_like, ones_like, full_like,
1515
normalize_store_arg)
@@ -996,7 +996,7 @@ def move(self, source, dest):
996996

997997

998998
def _normalize_store_arg(store, clobber=False):
999-
return normalize_store_arg(store, clobber=clobber, default=DictStore)
999+
return normalize_store_arg(store, clobber=clobber, default=MemoryStore)
10001000

10011001

10021002
def group(store=None, overwrite=False, chunk_store=None,

zarr/storage.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def _dict_store_keys(d, prefix='', cls=dict):
463463
yield prefix + k
464464

465465

466-
class DictStore(MutableMapping):
466+
class MemoryStore(MutableMapping):
467467
"""Store class that uses a hierarchy of :class:`dict` objects, thus all data
468468
will be held in main memory.
469469
@@ -474,7 +474,7 @@ class DictStore(MutableMapping):
474474
>>> import zarr
475475
>>> g = zarr.group()
476476
>>> type(g.store)
477-
<class 'zarr.storage.DictStore'>
477+
<class 'zarr.storage.MemoryStore'>
478478
479479
Note that the default class when creating an array is the built-in
480480
:class:`dict` class, i.e.::
@@ -568,7 +568,7 @@ def __contains__(self, item):
568568

569569
def __eq__(self, other):
570570
return (
571-
isinstance(other, DictStore) and
571+
isinstance(other, MemoryStore) and
572572
self.root == other.root and
573573
self.cls == other.cls
574574
)
@@ -656,6 +656,16 @@ def clear(self):
656656
self.root.clear()
657657

658658

659+
class DictStore(MemoryStore):
660+
661+
def __init__(self, *args, **kwargs):
662+
warnings.warn("DictStore has been renamed to MemoryStore and will be "
663+
"removed in the future. Please use MemoryStore.",
664+
DeprecationWarning,
665+
stacklevel=2)
666+
super(DictStore, self).__init__(*args, **kwargs)
667+
668+
659669
class DirectoryStore(MutableMapping):
660670
"""Storage class using directories and files on a standard file system.
661671

zarr/tests/test_convenience.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from zarr.convenience import (open, save, save_group, load, copy_store, copy,
1717
consolidate_metadata, open_consolidated)
18-
from zarr.storage import atexit_rmtree, DictStore, getsize, ConsolidatedMetadataStore
18+
from zarr.storage import atexit_rmtree, MemoryStore, getsize, ConsolidatedMetadataStore
1919
from zarr.core import Array
2020
from zarr.hierarchy import Group, group
2121
from zarr.errors import CopyError, PermissionError
@@ -96,7 +96,7 @@ def test_lazy_loader():
9696
def test_consolidate_metadata():
9797

9898
# setup initial data
99-
store = DictStore()
99+
store = MemoryStore()
100100
z = group(store)
101101
z.create_group('g1')
102102
g2 = z.create_group('g2')

zarr/tests/test_hierarchy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
asb = None
2121

2222

23-
from zarr.storage import (DictStore, DirectoryStore, ZipStore, init_group, init_array,
23+
from zarr.storage import (MemoryStore, DirectoryStore, ZipStore, init_group, init_array,
2424
array_meta_key, group_meta_key, atexit_rmtree,
2525
NestedDirectoryStore, DBMStore, LMDBStore, SQLiteStore,
2626
ABSStore, atexit_rmglob, LRUStoreCache)
@@ -852,11 +852,11 @@ def test_pickle(self):
852852
assert isinstance(g2['foo/bar'], Array)
853853

854854

855-
class TestGroupWithDictStore(TestGroup):
855+
class TestGroupWithMemoryStore(TestGroup):
856856

857857
@staticmethod
858858
def create_store():
859-
return DictStore(), None
859+
return MemoryStore(), None
860860

861861

862862
class TestGroupWithDirectoryStore(TestGroup):

zarr/tests/test_storage.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
asb = None
2323

2424

25-
from zarr.storage import (init_array, array_meta_key, attrs_key, DictStore,
25+
from zarr.storage import (init_array, array_meta_key, attrs_key, DictStore, MemoryStore,
2626
DirectoryStore, ZipStore, init_group, group_meta_key,
2727
getsize, migrate_1to2, TempStore, atexit_rmtree,
2828
NestedDirectoryStore, default_compressor, DBMStore,
@@ -652,7 +652,7 @@ def test_set_invalid_content(self):
652652
def setdel_hierarchy_checks(store):
653653
# these tests are for stores that are aware of hierarchy levels; this
654654
# behaviour is not stricly required by Zarr but these tests are included
655-
# to define behaviour of DictStore and DirectoryStore classes
655+
# to define behaviour of MemoryStore and DirectoryStore classes
656656

657657
# check __setitem__ and __delitem__ blocked by leaf
658658

@@ -686,10 +686,10 @@ def setdel_hierarchy_checks(store):
686686
assert 'r/s' not in store
687687

688688

689-
class TestDictStore(StoreTests, unittest.TestCase):
689+
class TestMemoryStore(StoreTests, unittest.TestCase):
690690

691691
def create_store(self):
692-
return DictStore()
692+
return MemoryStore()
693693

694694
def test_store_contains_bytes(self):
695695
store = self.create_store()
@@ -701,6 +701,17 @@ def test_setdel(self):
701701
setdel_hierarchy_checks(store)
702702

703703

704+
class TestDictStore(StoreTests, unittest.TestCase):
705+
706+
def create_store(self):
707+
return DictStore()
708+
709+
def test_deprecated(self):
710+
with pytest.warns(DeprecationWarning):
711+
store = self.create_store()
712+
assert isinstance(store, MemoryStore)
713+
714+
704715
class TestDirectoryStore(StoreTests, unittest.TestCase):
705716

706717
def create_store(self):

0 commit comments

Comments
 (0)