Skip to content

Commit 43d685b

Browse files
authored
DOC: Fixing EX01 - Added examples (#54324)
* Examples NumpyExtensionArray ... * After merge
1 parent 12c23c2 commit 43d685b

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

ci/code_checks.sh

-3
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6464
MSG='Partially validate docstrings (EX01)' ; echo $MSG
6565
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
6666
pandas.NaT \
67-
pandas.io.stata.StataReader.value_labels \
68-
pandas.io.stata.StataReader.variable_labels \
6967
pandas.io.stata.StataWriter.write_file \
7068
pandas.plotting.deregister_matplotlib_converters \
7169
pandas.plotting.register_matplotlib_converters \
7270
pandas.api.extensions.ExtensionArray \
73-
pandas.arrays.NumpyExtensionArray \
7471
RET=$(($RET + $?)) ; echo $MSG "DONE"
7572

7673
fi

pandas/core/arrays/numpy_.py

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ class NumpyExtensionArray( # type: ignore[misc]
7373
Methods
7474
-------
7575
None
76+
77+
Examples
78+
--------
79+
>>> pd.arrays.NumpyExtensionArray(np.array([0, 1, 2, 3]))
80+
<NumpyExtensionArray>
81+
[0, 1, 2, 3]
82+
Length: 4, dtype: int64
7683
"""
7784

7885
# If you're wondering why pd.Series(cls) doesn't put the array in an

pandas/io/stata.py

+32
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,22 @@ def variable_labels(self) -> dict[str, str]:
20632063
Returns
20642064
-------
20652065
dict
2066+
2067+
Examples
2068+
--------
2069+
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=["col_1", "col_2"])
2070+
>>> time_stamp = pd.Timestamp(2000, 2, 29, 14, 21)
2071+
>>> path = "/My_path/filename.dta"
2072+
>>> variable_labels = {"col_1": "This is an example"}
2073+
>>> df.to_stata(path, time_stamp=time_stamp, # doctest: +SKIP
2074+
... variable_labels=variable_labels, version=None) # doctest: +SKIP
2075+
>>> with pd.io.stata.StataReader(path) as reader: # doctest: +SKIP
2076+
... print(reader.variable_labels()) # doctest: +SKIP
2077+
{'index': '', 'col_1': 'This is an example', 'col_2': ''}
2078+
>>> pd.read_stata(path) # doctest: +SKIP
2079+
index col_1 col_2
2080+
0 0 1 2
2081+
1 1 3 4
20662082
"""
20672083
self._ensure_open()
20682084
return dict(zip(self._varlist, self._variable_labels))
@@ -2074,6 +2090,22 @@ def value_labels(self) -> dict[str, dict[float, str]]:
20742090
Returns
20752091
-------
20762092
dict
2093+
2094+
Examples
2095+
--------
2096+
>>> df = pd.DataFrame([[1, 2], [3, 4]], columns=["col_1", "col_2"])
2097+
>>> time_stamp = pd.Timestamp(2000, 2, 29, 14, 21)
2098+
>>> path = "/My_path/filename.dta"
2099+
>>> value_labels = {"col_1": {3: "x"}}
2100+
>>> df.to_stata(path, time_stamp=time_stamp, # doctest: +SKIP
2101+
... value_labels=value_labels, version=None) # doctest: +SKIP
2102+
>>> with pd.io.stata.StataReader(path) as reader: # doctest: +SKIP
2103+
... print(reader.value_labels()) # doctest: +SKIP
2104+
{'col_1': {3: 'x'}}
2105+
>>> pd.read_stata(path) # doctest: +SKIP
2106+
index col_1 col_2
2107+
0 0 1 2
2108+
1 1 x 4
20772109
"""
20782110
if not self._value_labels_read:
20792111
self._read_value_labels()

0 commit comments

Comments
 (0)