Skip to content

Commit c79e7ee

Browse files
KrishnaSai2020KrishnaSai2020
and
KrishnaSai2020
authored
TST: fix read_stata doctest #42670 (#42701)
* doctest fix for #42670 * added read_stata docstring into the doctests Co-authored-by: KrishnaSai2020 <[email protected]>
1 parent 7963422 commit c79e7ee

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

ci/code_checks.sh

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
123123
pandas/io/sql.py \
124124
pandas/io/formats/format.py \
125125
pandas/io/formats/style.py \
126+
pandas/io/stata.py \
126127
pandas/tseries/
127128
RET=$(($RET + $?)) ; echo $MSG "DONE"
128129

pandas/io/stata.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,30 @@
160160
161161
Examples
162162
--------
163+
164+
Creating a dummy stata for this example
165+
>>> df = pd.DataFrame({{'animal': ['falcon', 'parrot', 'falcon',
166+
... 'parrot'],
167+
... 'speed': [350, 18, 361, 15]}})
168+
>>> df.to_stata('animals.dta')
169+
163170
Read a Stata dta file:
164171
165-
>>> df = pd.read_stata('filename.dta')
172+
>>> df = pd.read_stata('animals.dta')
166173
167174
Read a Stata dta file in 10,000 line chunks:
175+
>>> values = np.random.randint(0, 10, size=(20_000, 1), dtype="uint8")
176+
>>> df = pd.DataFrame(values, columns=["i"])
177+
>>> df.to_stata('filename.dta')
168178
169179
>>> itr = pd.read_stata('filename.dta', chunksize=10000)
170180
>>> for chunk in itr:
171-
... do_something(chunk)
181+
... # Operate on a single chunk, e.g., chunk.mean()
182+
... pass
183+
184+
>>> import os
185+
>>> os.remove("./filename.dta")
186+
>>> os.remove("./animals.dta")
172187
"""
173188

174189
_read_method_doc = f"""\

0 commit comments

Comments
 (0)