From 2e96a0975e19292eb38d4e245d4464cd354b501a Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 1 Dec 2019 16:35:06 -0800 Subject: [PATCH 1/2] CLN: fix kwargs passing in _write_to_group --- pandas/io/pytables.py | 47 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 6ef821fc52d46..b5257203eef76 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1431,7 +1431,12 @@ def _validate_format(self, format: str, kwargs: Dict[str, Any]) -> Dict[str, Any return kwargs def _create_storer( - self, group, format=None, value=None, **kwargs + self, + group, + format=None, + value=None, + encoding: str = "UTF-8", + errors: str = "strict", ) -> Union["GenericFixed", "Table"]: """ return a suitable class to operate """ @@ -1439,8 +1444,7 @@ def error(t): # return instead of raising so mypy can tell where we are raising return TypeError( f"cannot properly create the storer for: [{t}] [group->" - f"{group},value->{type(value)},format->{format}," - f"kwargs->{kwargs}]" + f"{group},value->{type(value)},format->{format}" ) pt = _ensure_decoded(getattr(group._v_attrs, "pandas_type", None)) @@ -1476,7 +1480,9 @@ def error(t): # a storer node if "table" not in pt: try: - return globals()[_STORER_MAP[pt]](self, group, **kwargs) + return globals()[_STORER_MAP[pt]]( + self, group, encoding=encoding, errors=errors + ) except KeyError: raise error("_STORER_MAP") @@ -1517,7 +1523,9 @@ def error(t): pass try: - return globals()[_TABLE_MAP[tt]](self, group, **kwargs) + return globals()[_TABLE_MAP[tt]]( + self, group, encoding=encoding, errors=errors + ) except KeyError: raise error("_TABLE_MAP") @@ -1526,11 +1534,20 @@ def _write_to_group( key: str, value, format, + axes=None, index=True, append=False, complib=None, + complevel: Optional[int] = None, + fletcher32=None, + min_itemsize=None, + chunksize=None, + expectedrows=None, + dropna=False, + nan_rep=None, + data_columns=None, encoding=None, - **kwargs, + errors: str = "strict", ): group = self.get_node(key) @@ -1565,7 +1582,7 @@ def _write_to_group( group = self._handle.create_group(path, p) path = new_path - s = self._create_storer(group, format, value, encoding=encoding, **kwargs) + s = self._create_storer(group, format, value, encoding=encoding, errors=errors) if append: # raise if we are trying to append to a Fixed format, # or a table that exists (and we are putting) @@ -1580,7 +1597,20 @@ def _write_to_group( raise ValueError("Compression not supported on Fixed format stores") # write the object - s.write(obj=value, append=append, complib=complib, **kwargs) + s.write( + obj=value, + axes=axes, + append=append, + complib=complib, + complevel=complevel, + fletcher32=fletcher32, + min_itemsize=min_itemsize, + chunksize=chunksize, + expectedrows=expectedrows, + dropna=dropna, + nan_rep=nan_rep, + data_columns=data_columns, + ) if isinstance(s, Table) and index: s.create_index(columns=index) @@ -4076,7 +4106,6 @@ def write( dropna=False, nan_rep=None, data_columns=None, - errors="strict", # not used here, but passed to super ): if not append and self.is_exists: From 8ea819b93a6c830678b660bc04dcfd3d403b4a84 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Sun, 1 Dec 2019 16:37:24 -0800 Subject: [PATCH 2/2] remove unnecessary init kwargs --- pandas/io/pytables.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index b5257203eef76..dae9a01feeecf 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -2554,10 +2554,11 @@ class Fixed: ndim: int parent: HDFStore group: "Node" + errors: str is_table = False def __init__( - self, parent: HDFStore, group: "Node", encoding=None, errors="strict", **kwargs + self, parent: HDFStore, group: "Node", encoding=None, errors: str = "strict" ): assert isinstance(parent, HDFStore), type(parent) assert _table_mod is not None # needed for mypy @@ -3229,8 +3230,10 @@ class Table(Fixed): metadata: List info: Dict - def __init__(self, parent: HDFStore, group: "Node", **kwargs): - super().__init__(parent, group, **kwargs) + def __init__( + self, parent: HDFStore, group: "Node", encoding=None, errors: str = "strict" + ): + super().__init__(parent, group, encoding=encoding, errors=errors) self.index_axes = [] self.non_index_axes = [] self.values_axes = []