From 2d294a9cae6d7eac03d8fcbcef6bf0bb3c9eb2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 27 Jun 2023 16:04:23 +0200 Subject: [PATCH 1/3] Examples to_html, put, append --- pandas/core/frame.py | 5 +++++ pandas/io/pytables.py | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c7e8f74ff7849..68fa0024472f6 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3127,6 +3127,11 @@ def to_html( See Also -------- to_string : Convert DataFrame to a string. + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> df.to_html() # doctest: +SKIP """ if justify is not None and justify not in fmt._VALID_JUSTIFY_PARAMETERS: raise ValueError("Invalid value for justify parameter") diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index c9dab71805b62..64a2e96279d4d 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -1107,6 +1107,12 @@ def put( independent on creation time. dropna : bool, default False, optional Remove missing values. + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP + >>> store.put('data', df) # doctest: +SKIP """ if format is None: format = get_option("io.hdf.default_format") or "fixed" @@ -1243,6 +1249,20 @@ def append( ----- Does *not* check if data being appended overlaps with existing data in the table, so be careful + + Examples + -------- + >>> df1 = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP + >>> store.put('data', df1, format='table') # doctest: +SKIP + >>> df2 = pd.DataFrame([[5, 6], [7, 8]], columns=['A', 'B']) + >>> store.append('data', df2) # doctest: +SKIP + >>> store.close() # doctest: +SKIP + A B + 0 1 2 + 1 3 4 + 0 5 6 + 1 7 8 """ if columns is not None: raise TypeError( From e053bcfc009640b1241d0df82dbd07e6c63696fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 27 Jun 2023 16:38:48 +0200 Subject: [PATCH 2/3] Examples to_html, put, append, get, select, info, keys --- ci/code_checks.sh | 7 ------- pandas/io/pytables.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5870a9ad8d60b..9453edb0c88d8 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -108,14 +108,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.read_clipboard \ pandas.ExcelFile \ pandas.ExcelFile.parse \ - pandas.DataFrame.to_html \ pandas.io.formats.style.Styler.to_html \ - pandas.HDFStore.put \ - pandas.HDFStore.append \ - pandas.HDFStore.get \ - pandas.HDFStore.select \ - pandas.HDFStore.info \ - pandas.HDFStore.keys \ pandas.HDFStore.groups \ pandas.HDFStore.walk \ pandas.read_feather \ diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 64a2e96279d4d..eec5369baec0c 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -662,6 +662,16 @@ def keys(self, include: str = "pandas") -> list[str]: Raises ------ raises ValueError if kind has an illegal value + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP + >>> store.put('data', df) # doctest: +SKIP + >>> store.get('data') # doctest: +SKIP + >>> store.close() # doctest: +SKIP + >>> print(store.keys()) # doctest: +SKIP + ['/data1', '/data2'] """ if include == "pandas": return [n._v_pathname for n in self.groups()] @@ -781,6 +791,14 @@ def get(self, key: str): ------- object Same type as object stored in file. + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP + >>> store.put('data', df) # doctest: +SKIP + >>> store.get('data') # doctest: +SKIP + >>> store.close() # doctest: +SKIP """ with patch_pickle(): # GH#31167 Without this patch, pickle doesn't know how to unpickle @@ -835,6 +853,25 @@ def select( ------- object Retrieved object from file. + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP + >>> store.put('data', df) # doctest: +SKIP + >>> store.get('data') # doctest: +SKIP + >>> store.close() # doctest: +SKIP + >>> print(store.keys()) # doctest: +SKIP + ['/data1', '/data2'] + >>> store.select('/data1') # doctest: +SKIP + A B + 0 1 2 + 1 3 4 + >>> store.select('/data1', where='columns == A') # doctest: +SKIP + A + 0 1 + 1 3 + >>> store.close() # doctest: +SKIP """ group = self.get_node(key) if group is None: @@ -1598,6 +1635,17 @@ def info(self) -> str: Returns ------- str + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=['A', 'B']) + >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP + >>> store.put('data', df) # doctest: +SKIP + >>> print(store.info()) # doctest: +SKIP + >>> store.close() # doctest: +SKIP + + File path: store.h5 + /data frame (shape->[2,2]) """ path = pprint_thing(self._path) output = f"{type(self)}\nFile path: {path}\n" From 81edc66a54ab177eef730ab90654c53c3c6ee129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Tue, 27 Jun 2023 16:44:32 +0200 Subject: [PATCH 3/3] Correct select & keys --- pandas/io/pytables.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index eec5369baec0c..c37f2ba5114c4 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -669,9 +669,9 @@ def keys(self, include: str = "pandas") -> list[str]: >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP >>> store.put('data', df) # doctest: +SKIP >>> store.get('data') # doctest: +SKIP - >>> store.close() # doctest: +SKIP >>> print(store.keys()) # doctest: +SKIP ['/data1', '/data2'] + >>> store.close() # doctest: +SKIP """ if include == "pandas": return [n._v_pathname for n in self.groups()] @@ -860,7 +860,6 @@ def select( >>> store = pd.HDFStore("store.h5", 'w') # doctest: +SKIP >>> store.put('data', df) # doctest: +SKIP >>> store.get('data') # doctest: +SKIP - >>> store.close() # doctest: +SKIP >>> print(store.keys()) # doctest: +SKIP ['/data1', '/data2'] >>> store.select('/data1') # doctest: +SKIP