Skip to content

Commit 1928b09

Browse files
committed
Label stored results in do_inspect output
1 parent 75ccef5 commit 1928b09

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

nbs/03_stata_more.ipynb

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
"text": [
289289
"var1 __000001\n",
290290
"var1\n",
291-
"Elapsed time: 0.0007 seconds\n"
291+
"Elapsed time: 0.0005 seconds\n"
292292
]
293293
}
294294
],
@@ -802,8 +802,8 @@
802802
"name": "stdout",
803803
"output_type": "stream",
804804
"text": [
805-
"Elapsed time: 0.1930 seconds\n",
806-
"Elapsed time: 0.0948 seconds\n"
805+
"Elapsed time: 0.1942 seconds\n",
806+
"Elapsed time: 0.1100 seconds\n"
807807
]
808808
}
809809
],
@@ -826,7 +826,7 @@
826826
"name": "stdout",
827827
"output_type": "stream",
828828
"text": [
829-
"Elapsed time: 0.3255 seconds\n"
829+
"Elapsed time: 0.3189 seconds\n"
830830
]
831831
}
832832
],
@@ -1124,8 +1124,8 @@
11241124
"name": "stdout",
11251125
"output_type": "stream",
11261126
"text": [
1127-
"Elapsed time: 0.0024 seconds\n",
1128-
"Elapsed time: 0.2368 seconds\n"
1127+
"Elapsed time: 0.0023 seconds\n",
1128+
"Elapsed time: 0.2386 seconds\n"
11291129
]
11301130
}
11311131
],
@@ -1261,7 +1261,8 @@
12611261
"#| export\n",
12621262
"def get_inspect(code=\"\", cursor_pos=0, detail_level=0, omit_sections=()):\n",
12631263
" runner = functools.partial(run_as_program, prog_def_option_code=\"rclass\")\n",
1264-
" inspect_code = \"\"\"\\\n",
1264+
" inspect_code = \"\"\"\n",
1265+
" disp _newline \"*** Stored results:\"\n",
12651266
" return list\n",
12661267
" ereturn list\n",
12671268
" return add\n",
@@ -1270,7 +1271,10 @@
12701271
" \"\"\"\n",
12711272
" raw_output = diverted_stata_output(inspect_code, runner=runner)\n",
12721273
" desc_start = raw_output.find('*** Last updated ')\n",
1273-
" return raw_output[desc_start:] + raw_output[:desc_start]"
1274+
" out = raw_output[desc_start:]\n",
1275+
" if desc_start > 21:\n",
1276+
" out += raw_output[:desc_start]\n",
1277+
" return out"
12741278
]
12751279
},
12761280
{
@@ -1342,7 +1346,7 @@
13421346
"name": "stdout",
13431347
"output_type": "stream",
13441348
"text": [
1345-
"*** Last updated 12:28:02 18 Jan 2023 ***\n",
1349+
"*** Last updated 15:35:53 23 Jan 2023 ***\n",
13461350
"\n",
13471351
"Contains data\n",
13481352
" Observations: 5 \n",
@@ -1356,6 +1360,8 @@
13561360
"Sorted by: \n",
13571361
" Note: Dataset has changed since last saved.\n",
13581362
"\n",
1363+
"*** Stored results:\n",
1364+
"\n",
13591365
"scalars:\n",
13601366
" r(sum) = 2\n",
13611367
" r(max) = 1\n",
@@ -1387,6 +1393,23 @@
13871393
"run_sfi('return list')"
13881394
]
13891395
},
1396+
{
1397+
"cell_type": "code",
1398+
"execution_count": null,
1399+
"id": "5f5dc4cb",
1400+
"metadata": {},
1401+
"outputs": [],
1402+
"source": [
1403+
"#| eval: false\n",
1404+
"run_sfi('clear all')\n",
1405+
"test_eq(get_inspect()[43:],\"\"\"\\\n",
1406+
"Contains data\n",
1407+
" Observations: 0 \n",
1408+
" Variables: 0 \n",
1409+
"Sorted by: \n",
1410+
"\"\"\")"
1411+
]
1412+
},
13901413
{
13911414
"cell_type": "code",
13921415
"execution_count": null,

nbstata/stata_more.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def locals_code_from_dict(preexisting_local_dict):
147147
# %% ../nbs/03_stata_more.ipynb 73
148148
def get_inspect(code="", cursor_pos=0, detail_level=0, omit_sections=()):
149149
runner = functools.partial(run_as_program, prog_def_option_code="rclass")
150-
inspect_code = """\
150+
inspect_code = """
151+
disp _newline "*** Stored results:"
151152
return list
152153
ereturn list
153154
return add
@@ -156,4 +157,7 @@ def get_inspect(code="", cursor_pos=0, detail_level=0, omit_sections=()):
156157
"""
157158
raw_output = diverted_stata_output(inspect_code, runner=runner)
158159
desc_start = raw_output.find('*** Last updated ')
159-
return raw_output[desc_start:] + raw_output[:desc_start]
160+
out = raw_output[desc_start:]
161+
if desc_start > 21:
162+
out += raw_output[:desc_start]
163+
return out

0 commit comments

Comments
 (0)