def test_existing_arbitrary_collection_mdataframe(self): data = { 'foo': 'bar', 'bax': { 'fox': 'fax', } } store = OmegaStore() store.register_backend(PandasRawDictBackend.KIND, PandasRawDictBackend) foo_coll = store.mongodb['foo'] foo_coll.insert(data) store.make_metadata('myfoo', collection='foo', kind='pandas.rawdict').save() self.assertIn('myfoo', store.list()) # test we get back _id column if raw=True mdf = store.getl('myfoo', raw=True) self.assertIsInstance(mdf, MDataFrame) data_df = mdf.value data_raw = store.collection('myfoo').find_one() assert_frame_equal(json_normalize(data_raw), data_df) # test we get just the data column mdf = store.getl('myfoo', raw=False) self.assertIsInstance(mdf, MDataFrame) data_df = mdf.value data_raw = store.collection('myfoo').find_one() cols = ['foo', 'bax.fox'] assert_frame_equal(json_normalize(data)[cols], data_df[cols])
def test_existing_arbitrary_collection_flat(self): data = {'foo': 'bar', 'bax': 'fox'} store = OmegaStore() store.register_backend(PandasRawDictBackend.KIND, PandasRawDictBackend) foo_coll = store.mongodb['foo'] foo_coll.insert(data) store.make_metadata('myfoo', collection='foo', kind='pandas.rawdict').save() self.assertIn('myfoo', store.list()) # test we get back _id column if raw=True data_ = store.get('myfoo', raw=True) assert_frame_equal(json_normalize(data), data_) # test we get just the data column data_ = store.get('myfoo', raw=False) cols = ['foo', 'bax'] assert_frame_equal(json_normalize(data)[cols], data_[cols])