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

Function to_hdf

pandas/io/pytables.py:263–316  ·  view source on GitHub ↗

store this object, close it if we opened it

(
    path_or_buf: FilePath | HDFStore,
    key: str,
    value: DataFrame | Series,
    mode: str = "a",
    complevel: int | None = None,
    complib: str | None = None,
    append: bool = False,
    format: str | None = None,
    index: bool = True,
    min_itemsize: int | dict[str, int] | None = None,
    nan_rep=None,
    dropna: bool | None = None,
    data_columns: Literal[True] | list[str] | None = None,
    errors: str = "strict",
    encoding: str = "UTF-8",
)

Source from the content-addressed store, hash-verified

261
262
263def to_hdf(
264 path_or_buf: FilePath | HDFStore,
265 key: str,
266 value: DataFrame | Series,
267 mode: str = "a",
268 complevel: int | None = None,
269 complib: str | None = None,
270 append: bool = False,
271 format: str | None = None,
272 index: bool = True,
273 min_itemsize: int | dict[str, int] | None = None,
274 nan_rep=None,
275 dropna: bool | None = None,
276 data_columns: Literal[True] | list[str] | None = None,
277 errors: str = "strict",
278 encoding: str = "UTF-8",
279) -> None:
280 """store this object, close it if we opened it"""
281 if append:
282 f = lambda store: store.append(
283 key,
284 value,
285 format=format,
286 index=index,
287 min_itemsize=min_itemsize,
288 nan_rep=nan_rep,
289 dropna=dropna,
290 data_columns=data_columns,
291 errors=errors,
292 encoding=encoding,
293 )
294 else:
295 # NB: dropna is not passed to `put`
296 f = lambda store: store.put(
297 key,
298 value,
299 format=format,
300 index=index,
301 min_itemsize=min_itemsize,
302 nan_rep=nan_rep,
303 data_columns=data_columns,
304 errors=errors,
305 encoding=encoding,
306 dropna=dropna,
307 )
308
309 if isinstance(path_or_buf, HDFStore):
310 f(path_or_buf)
311 else:
312 path_or_buf = stringify_path(path_or_buf)
313 with HDFStore(
314 path_or_buf, mode=mode, complevel=complevel, complib=complib
315 ) as store:
316 f(store)
317
318
319@set_module("pandas")

Callers

nothing calls this directly

Calls 5

stringify_pathFunction · 0.90
HDFStoreClass · 0.85
putMethod · 0.80
fFunction · 0.70
appendMethod · 0.45

Tested by

no test coverage detected