Skip to content

Commit e306067

Browse files
committed
Switch to jupysql. Closes #2.
1 parent 9cadebd commit e306067

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

notebooks/3a_retrieval3.ipynb

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cells": [
33
{
4+
"attachments": {},
45
"cell_type": "markdown",
56
"metadata": {},
67
"source": [
@@ -20,7 +21,7 @@
2021
"metadata": {},
2122
"outputs": [],
2223
"source": [
23-
"import os\n",
24+
"from os import environ\n",
2425
"import urllib.parse\n",
2526
"\n",
2627
"from wrds.sql import (\n",
@@ -36,9 +37,9 @@
3637
"metadata": {},
3738
"outputs": [],
3839
"source": [
39-
"CONN = (\n",
40-
" f\"postgresql://{os.environ['WRDS_USER']}:\"\n",
41-
" f\"{urllib.parse.quote_plus(os.environ['WRDS_PASS'])}@\"\n",
40+
"environ[\"DATABASE_URL\"] = (\n",
41+
" f\"postgresql://{environ['WRDS_USER']}:\"\n",
42+
" f\"{urllib.parse.quote_plus(environ['WRDS_PASS'])}@\"\n",
4243
" f\"{WRDS_POSTGRES_HOST}:{WRDS_POSTGRES_PORT}/\"\n",
4344
" f\"{WRDS_POSTGRES_DB}\"\n",
4445
")"
@@ -72,10 +73,11 @@
7273
"metadata": {},
7374
"outputs": [],
7475
"source": [
75-
"%sql $CONN"
76+
"%sql"
7677
]
7778
},
7879
{
80+
"attachments": {},
7981
"cell_type": "markdown",
8082
"metadata": {},
8183
"source": [
@@ -96,6 +98,7 @@
9698
]
9799
},
98100
{
101+
"attachments": {},
99102
"cell_type": "markdown",
100103
"metadata": {},
101104
"source": [
@@ -170,6 +173,24 @@
170173
"df01.head() # noqa: F821"
171174
]
172175
},
176+
{
177+
"attachments": {},
178+
"cell_type": "markdown",
179+
"metadata": {},
180+
"source": [
181+
"## *Aside: code testing*\n",
182+
"\n",
183+
"(Feel free to skip)\n",
184+
"\n",
185+
"You may have noticed the comment, `# noqa: F821`, in the method call above.\n",
186+
"\n",
187+
"This is a specially-formatted comment that tells my testing infrastructure to ignore (i.e. no quality assurance, or noqa, error for the type F821, which corresponds with a `NameError`).\n",
188+
"The reason we need to capture it is that the code testing tool doesn't understand the `%%sql` magic commands, and it can't find where `df01` was previously defined.\n",
189+
"\n",
190+
"For a project of this scope and update frequency, it helps to have some automated testing that helps me catch when things stop working.\n",
191+
"One part of that is supressing errors that happen for some technical or intended reason, to isolate real problemsf."
192+
]
193+
},
173194
{
174195
"cell_type": "code",
175196
"execution_count": null,
@@ -181,6 +202,7 @@
181202
]
182203
},
183204
{
205+
"attachments": {},
184206
"cell_type": "markdown",
185207
"metadata": {},
186208
"source": [
@@ -215,6 +237,7 @@
215237
]
216238
},
217239
{
240+
"attachments": {},
218241
"cell_type": "markdown",
219242
"metadata": {},
220243
"source": [
@@ -248,6 +271,7 @@
248271
]
249272
},
250273
{
274+
"attachments": {},
251275
"cell_type": "markdown",
252276
"metadata": {},
253277
"source": [
@@ -259,6 +283,7 @@
259283
]
260284
},
261285
{
286+
"attachments": {},
262287
"cell_type": "markdown",
263288
"metadata": {},
264289
"source": [
@@ -297,6 +322,7 @@
297322
]
298323
},
299324
{
325+
"attachments": {},
300326
"cell_type": "markdown",
301327
"metadata": {},
302328
"source": [
@@ -330,6 +356,7 @@
330356
]
331357
},
332358
{
359+
"attachments": {},
333360
"cell_type": "markdown",
334361
"metadata": {},
335362
"source": [
@@ -343,6 +370,7 @@
343370
]
344371
},
345372
{
373+
"attachments": {},
346374
"cell_type": "markdown",
347375
"metadata": {},
348376
"source": [
@@ -380,6 +408,7 @@
380408
]
381409
},
382410
{
411+
"attachments": {},
383412
"cell_type": "markdown",
384413
"metadata": {},
385414
"source": [
@@ -394,6 +423,7 @@
394423
]
395424
},
396425
{
426+
"attachments": {},
397427
"cell_type": "markdown",
398428
"metadata": {},
399429
"source": [
@@ -440,7 +470,7 @@
440470
"name": "python",
441471
"nbconvert_exporter": "python",
442472
"pygments_lexer": "ipython3",
443-
"version": "3.11.2"
473+
"version": "3.11.3"
444474
},
445475
"vscode": {
446476
"interpreter": {

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ beautifulsoup4==4.11.2
22
geopandas==0.12.2
33
geopy==2.3.0
44
ipykernel==6.21.2
5-
ipython-sql==0.4.1
5+
jupysql==0.7.5
66
nbconvert==7.2.9
77
nbformat==5.7.3
88
pandas==1.5.3

0 commit comments

Comments
 (0)