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

Function test_reopen_handle

pandas/tests/io/pytables/test_file_handling.py:100–151  ·  view source on GitHub ↗
(temp_h5_path)

Source from the content-addressed store, hash-verified

98
99
100def test_reopen_handle(temp_h5_path):
101 store = HDFStore(temp_h5_path, mode="a")
102 store["a"] = Series(
103 np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
104 )
105
106 msg = (
107 r"Re-opening the file \[[\S]*\] with mode \[a\] will delete the "
108 "current file!"
109 )
110 # invalid mode change
111 with pytest.raises(PossibleDataLossError, match=msg):
112 store.open("w")
113
114 store.close()
115 assert not store.is_open
116
117 # truncation ok here
118 store.open("w")
119 assert store.is_open
120 assert len(store) == 0
121 store.close()
122 assert not store.is_open
123
124 store = HDFStore(temp_h5_path, mode="a")
125 store["a"] = Series(
126 np.arange(10, dtype=np.float64), index=date_range("2020-01-01", periods=10)
127 )
128
129 # reopen as read
130 store.open("r")
131 assert store.is_open
132 assert len(store) == 1
133 assert store._mode == "r"
134 store.close()
135 assert not store.is_open
136
137 # reopen as append
138 store.open("a")
139 assert store.is_open
140 assert len(store) == 1
141 assert store._mode == "a"
142 store.close()
143 assert not store.is_open
144
145 # reopen as append (again)
146 store.open("a")
147 assert store.is_open
148 assert len(store) == 1
149 assert store._mode == "a"
150 store.close()
151 assert not store.is_open
152
153
154def test_open_args(using_infer_string):

Callers

nothing calls this directly

Calls 6

openMethod · 0.95
closeMethod · 0.95
HDFStoreClass · 0.90
SeriesClass · 0.90
date_rangeFunction · 0.90
raisesMethod · 0.45

Tested by

no test coverage detected