From cbb0775a470ad676894513388f24d29a84de0843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 31 Jul 2023 17:59:34 +0200 Subject: [PATCH 1/2] Examples NumpyExtensionArray ... --- ci/code_checks.sh | 1 - pandas/core/arrays/numpy_.py | 7 +++++++ pandas/io/stata.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f6ed36b735cf4..e29f369804211 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -74,7 +74,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.plotting.register_matplotlib_converters \ pandas.api.extensions.ExtensionDtype \ pandas.api.extensions.ExtensionArray \ - pandas.arrays.NumpyExtensionArray \ RET=$(($RET + $?)) ; echo $MSG "DONE" fi diff --git a/pandas/core/arrays/numpy_.py b/pandas/core/arrays/numpy_.py index 6d01dfcf6d90b..bb426e931c53c 100644 --- a/pandas/core/arrays/numpy_.py +++ b/pandas/core/arrays/numpy_.py @@ -73,6 +73,13 @@ class NumpyExtensionArray( # type: ignore[misc] Methods ------- None + + Examples + -------- + >>> pd.arrays.NumpyExtensionArray(np.array([0, 1, 2, 3])) + + [0, 1, 2, 3] + Length: 4, dtype: int64 """ # If you're wondering why pd.Series(cls) doesn't put the array in an diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 633f67cac4643..3d0373ea27060 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -2050,6 +2050,22 @@ def variable_labels(self) -> dict[str, str]: Returns ------- dict + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=["col_1", "col_2"]) + >>> time_stamp = pd.Timestamp(2000, 2, 29, 14, 21) + >>> path = "/My_path/filename.dta" + >>> variable_labels = {"col_1": "This is an example"} + >>> df.to_stata(path, time_stamp=time_stamp, # doctest: +SKIP + ... variable_labels=variable_labels, version=None) # doctest: +SKIP + >>> with pd.io.stata.StataReader(path) as reader: # doctest: +SKIP + ... print(reader.variable_labels()) # doctest: +SKIP + {'index': '', 'col_1': 'This is an example', 'col_2': ''} + >>> pd.read_stata(path) # doctest: +SKIP + index col_1 col_2 + 0 0 1 2 + 1 1 3 4 """ self._ensure_open() return dict(zip(self._varlist, self._variable_labels)) @@ -2061,6 +2077,22 @@ def value_labels(self) -> dict[str, dict[float, str]]: Returns ------- dict + + Examples + -------- + >>> df = pd.DataFrame([[1, 2], [3, 4]], columns=["col_1", "col_2"]) + >>> time_stamp = pd.Timestamp(2000, 2, 29, 14, 21) + >>> path = "/My_path/filename.dta" + >>> value_labels = {"col_1": {3: "x"}} + >>> df.to_stata(path, time_stamp=time_stamp, # doctest: +SKIP + ... value_labels=value_labels, version=None) # doctest: +SKIP + >>> with pd.io.stata.StataReader(path) as reader: # doctest: +SKIP + ... print(reader.value_labels()) # doctest: +SKIP + {'col_1': {3: 'x'}} + >>> pd.read_stata(path) # doctest: +SKIP + index col_1 col_2 + 0 0 1 2 + 1 1 x 4 """ if not self._value_labels_read: self._read_value_labels() From 814f1f89992d7c4f058ee6e4fc6d2c5572661326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dea=20Mar=C3=ADa=20L=C3=A9on?= Date: Mon, 31 Jul 2023 18:16:02 +0200 Subject: [PATCH 2/2] After merge --- ci/code_checks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 39d7a67c0487e..7678e1e975d1a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -64,8 +64,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Partially validate docstrings (EX01)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \ pandas.NaT \ - pandas.io.stata.StataReader.value_labels \ - pandas.io.stata.StataReader.variable_labels \ pandas.io.stata.StataWriter.write_file \ pandas.plotting.deregister_matplotlib_converters \ pandas.plotting.register_matplotlib_converters \