|
1 | 1 | { |
2 | 2 | "cells": [ |
3 | 3 | { |
| 4 | + "attachments": {}, |
4 | 5 | "cell_type": "markdown", |
5 | 6 | "metadata": {}, |
6 | 7 | "source": [ |
|
20 | 21 | "metadata": {}, |
21 | 22 | "outputs": [], |
22 | 23 | "source": [ |
23 | | - "import os\n", |
| 24 | + "from os import environ\n", |
24 | 25 | "import urllib.parse\n", |
25 | 26 | "\n", |
26 | 27 | "from wrds.sql import (\n", |
|
36 | 37 | "metadata": {}, |
37 | 38 | "outputs": [], |
38 | 39 | "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", |
42 | 43 | " f\"{WRDS_POSTGRES_HOST}:{WRDS_POSTGRES_PORT}/\"\n", |
43 | 44 | " f\"{WRDS_POSTGRES_DB}\"\n", |
44 | 45 | ")" |
|
72 | 73 | "metadata": {}, |
73 | 74 | "outputs": [], |
74 | 75 | "source": [ |
75 | | - "%sql $CONN" |
| 76 | + "%sql" |
76 | 77 | ] |
77 | 78 | }, |
78 | 79 | { |
| 80 | + "attachments": {}, |
79 | 81 | "cell_type": "markdown", |
80 | 82 | "metadata": {}, |
81 | 83 | "source": [ |
|
96 | 98 | ] |
97 | 99 | }, |
98 | 100 | { |
| 101 | + "attachments": {}, |
99 | 102 | "cell_type": "markdown", |
100 | 103 | "metadata": {}, |
101 | 104 | "source": [ |
|
170 | 173 | "df01.head() # noqa: F821" |
171 | 174 | ] |
172 | 175 | }, |
| 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 | + }, |
173 | 194 | { |
174 | 195 | "cell_type": "code", |
175 | 196 | "execution_count": null, |
|
181 | 202 | ] |
182 | 203 | }, |
183 | 204 | { |
| 205 | + "attachments": {}, |
184 | 206 | "cell_type": "markdown", |
185 | 207 | "metadata": {}, |
186 | 208 | "source": [ |
|
215 | 237 | ] |
216 | 238 | }, |
217 | 239 | { |
| 240 | + "attachments": {}, |
218 | 241 | "cell_type": "markdown", |
219 | 242 | "metadata": {}, |
220 | 243 | "source": [ |
|
248 | 271 | ] |
249 | 272 | }, |
250 | 273 | { |
| 274 | + "attachments": {}, |
251 | 275 | "cell_type": "markdown", |
252 | 276 | "metadata": {}, |
253 | 277 | "source": [ |
|
259 | 283 | ] |
260 | 284 | }, |
261 | 285 | { |
| 286 | + "attachments": {}, |
262 | 287 | "cell_type": "markdown", |
263 | 288 | "metadata": {}, |
264 | 289 | "source": [ |
|
297 | 322 | ] |
298 | 323 | }, |
299 | 324 | { |
| 325 | + "attachments": {}, |
300 | 326 | "cell_type": "markdown", |
301 | 327 | "metadata": {}, |
302 | 328 | "source": [ |
|
330 | 356 | ] |
331 | 357 | }, |
332 | 358 | { |
| 359 | + "attachments": {}, |
333 | 360 | "cell_type": "markdown", |
334 | 361 | "metadata": {}, |
335 | 362 | "source": [ |
|
343 | 370 | ] |
344 | 371 | }, |
345 | 372 | { |
| 373 | + "attachments": {}, |
346 | 374 | "cell_type": "markdown", |
347 | 375 | "metadata": {}, |
348 | 376 | "source": [ |
|
380 | 408 | ] |
381 | 409 | }, |
382 | 410 | { |
| 411 | + "attachments": {}, |
383 | 412 | "cell_type": "markdown", |
384 | 413 | "metadata": {}, |
385 | 414 | "source": [ |
|
394 | 423 | ] |
395 | 424 | }, |
396 | 425 | { |
| 426 | + "attachments": {}, |
397 | 427 | "cell_type": "markdown", |
398 | 428 | "metadata": {}, |
399 | 429 | "source": [ |
|
440 | 470 | "name": "python", |
441 | 471 | "nbconvert_exporter": "python", |
442 | 472 | "pygments_lexer": "ipython3", |
443 | | - "version": "3.11.2" |
| 473 | + "version": "3.11.3" |
444 | 474 | }, |
445 | 475 | "vscode": { |
446 | 476 | "interpreter": { |
|
0 commit comments