Skip to content

CLN: explicit kwargs for select #29977

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

Merged
merged 1 commit 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
38 changes: 30 additions & 8 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,19 @@ def to_hdf(
f(path_or_buf)


def read_hdf(path_or_buf, key=None, mode: str = "r", **kwargs):
def read_hdf(
path_or_buf,
key=None,
mode: str = "r",
errors: str = "strict",
where=None,
start: Optional[int] = None,
stop: Optional[int] = None,
columns=None,
iterator=False,
chunksize: Optional[int] = None,
**kwargs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a solution to this would be to remove kwargs and instead add a keyword backend_kwargs={} or driver_kwargs={}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would work, will need deprecation cycle, and im all about removing deprecations these days

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now ill need to make a quick PR reverting the assert not kwargs this introduced

):
"""
Read from the store, close it if we opened it.

Expand Down Expand Up @@ -350,15 +362,18 @@ def read_hdf(path_or_buf, key=None, mode: str = "r", **kwargs):
>>> df.to_hdf('./store.h5', 'data')
>>> reread = pd.read_hdf('./store.h5')
"""
assert not kwargs, kwargs
# NB: in principle more kwargs could be passed to HDFStore, but in
# tests none are.

if mode not in ["r", "r+", "a"]:
raise ValueError(
f"mode {mode} is not allowed while performing a read. "
f"Allowed modes are r, r+ and a."
)
# grab the scope
if "where" in kwargs:
kwargs["where"] = _ensure_term(kwargs["where"], scope_level=1)
if where is not None:
where = _ensure_term(where, scope_level=1)

if isinstance(path_or_buf, HDFStore):
if not path_or_buf.is_open:
Expand All @@ -382,7 +397,7 @@ def read_hdf(path_or_buf, key=None, mode: str = "r", **kwargs):
if not exists:
raise FileNotFoundError(f"File {path_or_buf} does not exist")

store = HDFStore(path_or_buf, mode=mode, **kwargs)
store = HDFStore(path_or_buf, mode=mode, errors=errors, **kwargs)
# can't auto open/close if we are using an iterator
# so delegate to the iterator
auto_close = True
Expand All @@ -405,7 +420,16 @@ def read_hdf(path_or_buf, key=None, mode: str = "r", **kwargs):
"contains multiple datasets."
)
key = candidate_only_group._v_pathname
return store.select(key, auto_close=auto_close, **kwargs)
return store.select(
key,
where=where,
start=start,
stop=stop,
columns=columns,
iterator=iterator,
chunksize=chunksize,
auto_close=auto_close,
)
except (ValueError, TypeError, KeyError):
if not isinstance(path_or_buf, HDFStore):
# if there is an error, close the store if we opened it.
Expand Down Expand Up @@ -734,7 +758,6 @@ def select(
iterator=False,
chunksize=None,
auto_close: bool = False,
**kwargs,
):
"""
Retrieve pandas object stored in file, optionally based on where criteria.
Expand Down Expand Up @@ -850,7 +873,6 @@ def select_as_multiple(
iterator=False,
chunksize=None,
auto_close: bool = False,
**kwargs,
):
"""
Retrieve pandas objects from multiple tables.
Expand Down Expand Up @@ -888,7 +910,7 @@ def select_as_multiple(
stop=stop,
iterator=iterator,
chunksize=chunksize,
**kwargs,
auto_close=auto_close,
)

if not isinstance(keys, (list, tuple)):
Expand Down