8000 Fix Sqlite Store Wrong Modification (#440) · sailfish009/zarr-python@66ac090 · GitHub
[go: up one dir, main page]

Skip to content

Commit 66ac090

Browse files
potter420jakirkham
authored andcommitted
Fix Sqlite Store Wrong Modification (zarr-developers#440)
* Fix Sqlite Store Wrong Modification Reference to issue zarr-developers#439 * PEP8 compliance Line 2186:26: E225 missing whitespace around operator * Travis CI Coverage Changes to comply with travis build * Added tests Added test for zarr-developers#439 , underscore character in array name * Fix Test * Fix test for travis
1 parent 4992c0c commit 66ac090

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

zarr/storage.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,13 +2265,14 @@ def update(self, *args, **kwargs):
22652265

22662266
def listdir(self, path=None):
22672267
path = normalize_storage_path(path)
2268+
sep = '_' if path == '' else '/'
22682269
keys = self.cursor.execute(
22692270
'''
22702271
SELECT DISTINCT SUBSTR(m, 0, INSTR(m, "/")) AS l FROM (
22712272
SELECT LTRIM(SUBSTR(k, LENGTH(?) + 1), "/") || "/" AS m
2272-
FROM zarr WHERE k LIKE (? || "_%")
2273+
FROM zarr WHERE k LIKE (? || "{sep}%")
22732274
) ORDER BY l ASC
2274-
''',
2275+
'''.format(sep=sep),
22752276
(path, path)
22762277
)
22772278
keys = list(map(operator.itemgetter(0), keys))
@@ -2295,7 +2296,7 @@ def rmdir(self, path=None):
22952296
if path:
22962297
with self.lock:
22972298
self.cursor.execute(
2298-
'DELETE FROM zarr WHERE k LIKE (? || "_%")', (path,)
2299+
'DELETE FROM zarr WHERE k LIKE (? || "/%")', (path,)
22992300
)
23002301
else:
23012302
self.clear()

zarr/tests/test_storage.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,15 @@ def create_store(self):
10491049
store = SQLiteStore(path)
10501050
return store
10511051

1052+
def test_underscore_in_name(self):
1053+
path = tempfile.mktemp(suffix='.db')
1054+
atexit.register(atexit_rmtree, path)
1055+
store = SQLiteStore(path)
1056+
store['a'] = b'aaa'
1057+
store['a_b'] = b'aa_bb'
1058+
store.rmdir('a')
1059+
assert 'a_b' in store
1060+
10521061

10531062
class TestSQLiteStoreInMemory(TestSQLiteStore, unittest.TestCase):
10541063

0 commit comments

Comments
 (0)
0