Skip to content

Commit 8e18bd2

Browse files
authored
Merge pull request pandas-dev#389 from manahl/issue-343
Renaming libraries within a database/namespace
2 parents 16d479e + e3bd0fe commit 8e18bd2

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### 1.49
44
* Bugfix: #384 sentinels missing time data on chunk start/ends in ChunkStore
55
* Bugfix: #382 Remove dependency on cython being pre-installed
6+
* Bugfix: #343 Renaming libraries/collections within a namespace/database
67

78
### 1.48 (2017-06-26)
89
* BugFix: Rollback #363, as it breaks multi-index dataframe

arctic/arctic.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,21 @@ def rename_library(self, from_lib, to_lib):
322322
to_lib: str
323323
The new name of the library
324324
"""
325+
to_colname = to_lib
326+
if '.' in from_lib and '.' in to_lib:
327+
if from_lib.split('.')[0] != to_lib.split('.')[0]:
328+
raise ValueError("Collection can only be renamed in the same database")
329+
to_colname = to_lib.split('.')[1]
330+
325331
l = ArcticLibraryBinding(self, from_lib)
326332
colname = l.get_top_level_collection().name
327-
logger.info('Dropping collection: %s' % colname)
328-
l._db[colname].rename(to_lib)
333+
334+
logger.info('Renaming collection: %s' % colname)
335+
l._db[colname].rename(to_colname)
329336
for coll in l._db.collection_names():
330337
if coll.startswith(colname + '.'):
331-
l._db[coll].rename(coll.replace(from_lib, to_lib))
338+
l._db[coll].rename(coll.replace(colname, to_colname))
339+
332340
if from_lib in self._library_cache:
333341
del self._library_cache[from_lib]
334342
del self._library_cache[l.get_name()]

tests/integration/test_arctic.py

+19
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,25 @@ def test_lib_rename(arctic):
168168
assert('test' not in arctic.list_libraries())
169169

170170

171+
def test_lib_rename_namespace(arctic):
172+
arctic.initialize_library('namespace.test')
173+
l = arctic['namespace.test']
174+
l.write('test_data', 'abc')
175+
176+
with pytest.raises(ValueError) as e:
177+
arctic.rename_library('namespace.test', 'new_namespace.test')
178+
assert('Collection can only be renamed in the same database' in str(e))
179+
180+
arctic.rename_library('namespace.test', 'namespace.newlib')
181+
l = arctic['namespace.newlib']
182+
assert(l.read('test_data').data == 'abc')
183+
184+
with pytest.raises(LibraryNotFoundException) as e:
185+
l = arctic['namespace.test']
186+
assert('Library namespace.test' in str(e))
187+
assert('namespace.test' not in arctic.list_libraries())
188+
189+
171190
def test_lib_type(arctic):
172191
arctic.initialize_library('test')
173192
assert(arctic.get_library_type('test') == VERSION_STORE)

0 commit comments

Comments
 (0)