MCPcopy
hub / github.com/pandas-dev/pandas / test_walk

Function test_walk

pandas/tests/io/pytables/test_store.py:256–293  ·  view source on GitHub ↗
(where, expected, temp_hdfstore)

Source from the content-addressed store, hash-verified

254 ],
255)
256def test_walk(where, expected, temp_hdfstore):
257 # GH10143
258 objs = {
259 "df1": DataFrame([1, 2, 3]),
260 "df2": DataFrame([4, 5, 6]),
261 "df3": DataFrame([6, 7, 8]),
262 "df4": DataFrame([9, 10, 11]),
263 "s1": Series([10, 9, 8]),
264 # Next 3 items aren't pandas objects and should be ignored
265 "a1": np.array([[1, 2, 3], [4, 5, 6]]),
266 "tb1": np.array([(1, 2, 3), (4, 5, 6)], dtype="i,i,i"),
267 "tb2": np.array([(7, 8, 9), (10, 11, 12)], dtype="i,i,i"),
268 }
269
270 store = temp_hdfstore
271 store.put("/first_group/df1", objs["df1"])
272 store.put("/first_group/df2", objs["df2"])
273 store.put("/second_group/df3", objs["df3"])
274 store.put("/second_group/s1", objs["s1"])
275 store.put("/second_group/third_group/df4", objs["df4"])
276 # Create non-pandas objects
277 store._handle.create_array("/first_group", "a1", objs["a1"])
278 store._handle.create_table("/first_group", "tb1", obj=objs["tb1"])
279 store._handle.create_table("/second_group", "tb2", obj=objs["tb2"])
280
281 assert len(list(store.walk(where=where))) == len(expected)
282 for path, groups, leaves in store.walk(where=where):
283 assert path in expected
284 expected_groups, expected_frames = expected[path]
285 assert expected_groups == set(groups)
286 assert expected_frames == set(leaves)
287 for leaf in leaves:
288 frame_path = "/".join([path, leaf])
289 obj = store.get(frame_path)
290 if "df" in leaf:
291 tm.assert_frame_equal(obj, objs[leaf])
292 else:
293 tm.assert_series_equal(obj, objs[leaf])
294
295
296def test_getattr(temp_hdfstore):

Callers

nothing calls this directly

Calls 7

DataFrameClass · 0.90
SeriesClass · 0.90
putMethod · 0.80
walkMethod · 0.80
arrayMethod · 0.45
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected