Skip to content

Commit 76738f9

Browse files
Changed new keyword parameter 'kind' to 'include'
1 parent eabed52 commit 76738f9

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ I/O
340340
- Bug in :class:`HDFStore` that caused it to set to ``int64`` the dtype of a ``datetime64`` column when reading a DataFrame in Python 3 from fixed format written in Python 2 (:issue:`31750`)
341341
- Bug in :meth:`read_excel` where a UTF-8 string with a high surrogate would cause a segmentation violation (:issue:`23809`)
342342
- Bug in :meth:`read_csv` was causing a file descriptor leak on an empty file (:issue:`31488`)
343-
- :meth:`HDFStore.keys` has now an optional `kind` parameter that allows the retrieval of all native HDF5 table names (:issue:`29916`)
343+
- :meth:`HDFStore.keys` has now an optional `include` parameter that allows the retrieval of all native HDF5 table names (:issue:`29916`)
344344

345345

346346
Plotting

pandas/io/pytables.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -580,15 +580,15 @@ def __enter__(self):
580580
def __exit__(self, exc_type, exc_value, traceback):
581581
self.close()
582582

583-
def keys(self, kind: Optional[str] = "pandas") -> List[str]:
583+
def keys(self, include: Optional[str] = "pandas") -> List[str]:
584584
"""
585585
Return a list of keys corresponding to objects stored in HDFStore.
586586
587587
Parameters
588588
----------
589-
kind : str, default 'pandas'
589+
include : str, default 'pandas'
590590
When kind equals 'pandas' return pandas objects
591-
When kind equals 'table' return Table objects
591+
When kind equals 'native' return native HDF5 Table objects
592592
Otherwise fail with a ValueError
593593
594594
Returns
@@ -600,15 +600,17 @@ def keys(self, kind: Optional[str] = "pandas") -> List[str]:
600600
------
601601
raises ValueError if kind has an illegal value
602602
"""
603-
if kind == "pandas":
603+
if include == "pandas":
604604
return [n._v_pathname for n in self.groups()]
605605

606-
if kind == "tables":
607-
self._check_if_open()
606+
if include == "native":
607+
assert self._handle is not None # mypy
608608
return [
609609
n._v_pathname for n in self._handle.walk_nodes("/", classname="Table")
610610
]
611-
raise ValueError(f"`kind` should be either 'pandas' or 'table' but is [{kind}]")
611+
raise ValueError(
612+
f"`include` should be either 'pandas' or 'native' but is [{include}]"
613+
)
612614

613615
def __iter__(self):
614616
return iter(self.keys())

pandas/tests/io/pytables/test_store.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ class Table3(tables.IsDescription):
313313
h5file.create_table(group, "table2", Table2, "Table 2")
314314
h5file.create_table(group, "table3", Table3, "Table 3")
315315
with HDFStore(path) as store:
316-
assert len(store.keys(kind="tables")) == 3
316+
assert len(store.keys(include="native")) == 3
317317
expected = {"/group/table1", "/group/table2", "/group/table3"}
318-
assert set(store.keys(kind="tables")) == expected
319-
assert set(store.keys(kind="pandas")) == set()
318+
assert set(store.keys(include="native")) == expected
319+
assert set(store.keys(include="pandas")) == set()
320320

321321
def test_keys_ignore_hdf_softlink(self, setup_path):
322322

0 commit comments

Comments
 (0)