Skip to content

Commit 751cb70

Browse files
jbrockmendelproost
authored andcommitted
Make kwargs explicit in put, append (pandas-dev#29957)
1 parent 94da194 commit 751cb70

File tree

2 files changed

+97
-14
lines changed

2 files changed

+97
-14
lines changed

pandas/core/generic.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -2413,9 +2413,13 @@ def to_hdf(
24132413
complib: Optional[str] = None,
24142414
append: bool_t = False,
24152415
format: Optional[str] = None,
2416+
index: bool_t = True,
2417+
min_itemsize: Optional[Union[int, Dict[str, int]]] = None,
2418+
nan_rep=None,
2419+
dropna: Optional[bool_t] = None,
2420+
data_columns: Optional[List[str]] = None,
24162421
errors: str = "strict",
24172422
encoding: str = "UTF-8",
2418-
**kwargs,
24192423
):
24202424
"""
24212425
Write the contained data to an HDF5 file using HDFStore.
@@ -2472,15 +2476,16 @@ def to_hdf(
24722476
See the errors argument for :func:`open` for a full list
24732477
of options.
24742478
encoding : str, default "UTF-8"
2479+
min_itemsize : dict or int, optional
2480+
Map column names to minimum string sizes for columns.
2481+
nan_rep : Any, optional
2482+
How to represent null values as str.
2483+
Not allowed with append=True.
24752484
data_columns : list of columns or True, optional
24762485
List of columns to create as indexed data columns for on-disk
24772486
queries, or True to use all columns. By default only the axes
24782487
of the object are indexed. See :ref:`io.hdf5-query-data-columns`.
24792488
Applicable only to format='table'.
2480-
fletcher32 : bool, default False
2481-
If applying compression use the fletcher32 checksum.
2482-
dropna : bool, default False
2483-
If true, ALL nan rows will not be written to store.
24842489
24852490
See Also
24862491
--------
@@ -2531,9 +2536,13 @@ def to_hdf(
25312536
complib=complib,
25322537
append=append,
25332538
format=format,
2539+
index=index,
2540+
min_itemsize=min_itemsize,
2541+
nan_rep=nan_rep,
2542+
dropna=dropna,
2543+
data_columns=data_columns,
25342544
errors=errors,
25352545
encoding=encoding,
2536-
**kwargs,
25372546
)
25382547

25392548
def to_msgpack(self, path_or_buf=None, encoding="utf-8", **kwargs):

pandas/io/pytables.py

+82-8
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,41 @@ def to_hdf(
260260
complib: Optional[str] = None,
261261
append: bool = False,
262262
format: Optional[str] = None,
263+
index: bool = True,
264+
min_itemsize: Optional[Union[int, Dict[str, int]]] = None,
265+
nan_rep=None,
266+
dropna: Optional[bool] = None,
267+
data_columns: Optional[List[str]] = None,
263268
errors: str = "strict",
264269
encoding: str = "UTF-8",
265-
**kwargs,
266270
):
267271
""" store this object, close it if we opened it """
268272

269273
if append:
270274
f = lambda store: store.append(
271-
key, value, format=format, errors=errors, encoding=encoding, **kwargs
275+
key,
276+
value,
277+
format=format,
278+
index=index,
279+
min_itemsize=min_itemsize,
280+
nan_rep=nan_rep,
281+
dropna=dropna,
282+
data_columns=data_columns,
283+
errors=errors,
284+
encoding=encoding,
272285
)
273286
else:
287+
# NB: dropna is not passed to `put`
274288
f = lambda store: store.put(
275-
key, value, format=format, errors=errors, encoding=encoding, **kwargs
289+
key,
290+
value,
291+
format=format,
292+
index=index,
293+
min_itemsize=min_itemsize,
294+
nan_rep=nan_rep,
295+
data_columns=data_columns,
296+
errors=errors,
297+
encoding=encoding,
276298
)
277299

278300
path_or_buf = _stringify_path(path_or_buf)
@@ -984,7 +1006,21 @@ def func(_start, _stop, _where):
9841006

9851007
return it.get_result(coordinates=True)
9861008

987-
def put(self, key: str, value: FrameOrSeries, format=None, append=False, **kwargs):
1009+
def put(
1010+
self,
1011+
key: str,
1012+
value: FrameOrSeries,
1013+
format=None,
1014+
index=True,
1015+
append=False,
1016+
complib=None,
1017+
complevel: Optional[int] = None,
1018+
min_itemsize: Optional[Union[int, Dict[str, int]]] = None,
1019+
nan_rep=None,
1020+
data_columns: Optional[List[str]] = None,
1021+
encoding=None,
1022+
errors: str = "strict",
1023+
):
9881024
"""
9891025
Store object in HDFStore.
9901026
@@ -1014,7 +1050,20 @@ def put(self, key: str, value: FrameOrSeries, format=None, append=False, **kwarg
10141050
if format is None:
10151051
format = get_option("io.hdf.default_format") or "fixed"
10161052
format = self._validate_format(format)
1017-
self._write_to_group(key, value, format=format, append=append, **kwargs)
1053+
self._write_to_group(
1054+
key,
1055+
value,
1056+
format=format,
1057+
index=index,
1058+
append=append,
1059+
complib=complib,
1060+
complevel=complevel,
1061+
min_itemsize=min_itemsize,
1062+
nan_rep=nan_rep,
1063+
data_columns=data_columns,
1064+
encoding=encoding,
1065+
errors=errors,
1066+
)
10181067

10191068
def remove(self, key: str, where=None, start=None, stop=None):
10201069
"""
@@ -1075,10 +1124,20 @@ def append(
10751124
key: str,
10761125
value: FrameOrSeries,
10771126
format=None,
1127+
axes=None,
1128+
index=True,
10781129
append=True,
1130+
complib=None,
1131+
complevel: Optional[int] = None,
10791132
columns=None,
1133+
min_itemsize: Optional[Union[int, Dict[str, int]]] = None,
1134+
nan_rep=None,
1135+
chunksize=None,
1136+
expectedrows=None,
10801137
dropna: Optional[bool] = None,
1081-
**kwargs,
1138+
data_columns: Optional[List[str]] = None,
1139+
encoding=None,
1140+
errors: str = "strict",
10821141
):
10831142
"""
10841143
Append to Table in file. Node must already exist and be Table
@@ -1125,7 +1184,22 @@ def append(
11251184
format = get_option("io.hdf.default_format") or "table"
11261185
format = self._validate_format(format)
11271186
self._write_to_group(
1128-
key, value, format=format, append=append, dropna=dropna, **kwargs
1187+
key,
1188+
value,
1189+
format=format,
1190+
axes=axes,
1191+
index=index,
1192+
append=append,
1193+
complib=complib,
1194+
complevel=complevel,
1195+
min_itemsize=min_itemsize,
1196+
nan_rep=nan_rep,
1197+
chunksize=chunksize,
1198+
expectedrows=expectedrows,
1199+
dropna=dropna,
1200+
data_columns=data_columns,
1201+
encoding=encoding,
1202+
errors=errors,
11291203
)
11301204

11311205
def append_to_multiple(
@@ -1586,7 +1660,7 @@ def _write_to_group(
15861660
complib=None,
15871661
complevel: Optional[int] = None,
15881662
fletcher32=None,
1589-
min_itemsize=None,
1663+
min_itemsize: Optional[Union[int, Dict[str, int]]] = None,
15901664
chunksize=None,
15911665
expectedrows=None,
15921666
dropna=False,

0 commit comments

Comments
 (0)