Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: fix pytables passing too many kwargs #29951

Merged
merged 2 commits into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 44 additions & 12 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,16 +1431,20 @@ 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 """

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))
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -2524,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
Expand Down Expand Up @@ -3199,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 = []
Expand Down Expand Up @@ -4076,7 +4109,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:
Expand Down