Skip to content

Commit e963468

Browse files
authored
Add rename support for Libraries in Arctic (pandas-dev#225)
1 parent 979d39f commit e963468

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

arctic/arctic.py

+22
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,28 @@ def check_quota(self, library):
302302
l = ArcticLibraryBinding(self, library)
303303
l.check_quota()
304304

305+
def rename_library(self, from_lib, to_lib):
306+
"""
307+
Renames a library
308+
309+
Parameters
310+
----------
311+
from_lib: str
312+
The name of the library to be renamed
313+
to_lib: str
314+
The new name of the library
315+
"""
316+
l = ArcticLibraryBinding(self, from_lib)
317+
colname = l.get_top_level_collection().name
318+
logger.info('Dropping collection: %s' % colname)
319+
l._db[colname].rename(to_lib)
320+
for coll in l._db.collection_names():
321+
if coll.startswith(colname + '.'):
322+
l._db[coll].rename(coll.replace(from_lib, to_lib))
323+
if from_lib in self._library_cache:
324+
del self._library_cache[from_lib]
325+
del self._library_cache[l.get_name()]
326+
305327

306328
class ArcticLibraryBinding(object):
307329
"""

tests/integration/test_arctic.py

+13
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,16 @@ def test_default_mongo_retry_timout():
144144
with pytest.raises(LibraryNotFoundException):
145145
Arctic('unresolved-host', serverSelectionTimeoutMS=0)['some.lib']
146146
assert time.time() - now < 1.
147+
148+
149+
def test_lib_rename(arctic):
150+
arctic.initialize_library('test')
151+
l = arctic['test']
152+
l.write('test_data', 'abc')
153+
arctic.rename_library('test', 'new_name')
154+
l = arctic['new_name']
155+
assert(l.read('test_data').data == 'abc')
156+
with pytest.raises(LibraryNotFoundException) as e:
157+
l = arctic['test']
158+
assert('Library test' in str(e))
159+
assert('test' not in arctic.list_libraries())

0 commit comments

Comments
 (0)