Skip to content

Commit bdb8b0d

Browse files
committed
Upgrade Python version to 3.12 and update dependencies; replace pandas-datareader with pyfredapi in notebooks.
1 parent 7039525 commit bdb8b0d

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "carmapy",
3-
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm",
3+
"image": "mcr.microsoft.com/devcontainers/python:3.12-bookworm",
44
"features": {
55
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:latest": {
66
"version": "prerelease"
@@ -18,6 +18,7 @@
1818
"postCreateCommand": "zsh ./.devcontainer/post_create.sh",
1919
"containerEnv": {
2020
"API_NYT": "${localEnv:API_NYT}",
21+
"FRED_API_KEY": "${localEnv:FRED_API_KEY}",
2122
"WRDS_USER": "${localEnv:WRDS_USER}",
2223
"WRDS_PASS": "${localEnv:WRDS_PASS}"
2324
}

.github/workflows/test_notebooks.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: [push]
44

55
env:
66
API_NYT: ${{ secrets.API_NYT }}
7+
FRED_API_KEY: ${{ secrets.FRED_API_KEY }}
78
WRDS_USER: ${{ secrets.WRDS_USER }}
89
WRDS_PASS: ${{ secrets.WRDS_PASS }}
910

@@ -13,7 +14,7 @@ jobs:
1314
runs-on: ubuntu-latest
1415
strategy:
1516
matrix:
16-
python-version: ["3.11"]
17+
python-version: ["3.12"]
1718

1819
steps:
1920
- uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ repos:
55
- id: black
66
- id: black-jupyter
77
- repo: https://github.com/nbQA-dev/nbQA
8-
rev: 1.6.3
8+
rev: 1.9.1
99
hooks:
1010
- id: nbqa-ruff
11-
additional_dependencies: [ruff==0.0.256]
12-
- repo: https://github.com/charliermarsh/ruff-pre-commit
13-
rev: v0.0.256
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.9.10
1413
hooks:
1514
- id: ruff
1615
args: [--exit-non-zero-on-fix]

notebooks/2c_retrieval2.ipynb

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"In this notebook, we will work with the following:\n",
1212
"\n",
1313
"- API access.\n",
14-
"- pandas-datareader\n",
14+
" - NYTimes API.\n",
15+
" - FRED API.\n",
1516
"- Commercial databases.\n",
1617
"- SQL."
1718
]
@@ -27,7 +28,7 @@
2728
"\n",
2829
"import plotly.express as px\n",
2930
"import pandas as pd\n",
30-
"import pandas_datareader as pdr\n",
31+
"import pyfredapi as pf\n",
3132
"from pynytimes import NYTAPI"
3233
]
3334
},
@@ -130,12 +131,17 @@
130131
"cell_type": "markdown",
131132
"metadata": {},
132133
"source": [
133-
"# pandas-datareader\n",
134+
"# FRED\n",
134135
"\n",
135-
"The `pandas-datareader` package provides access to a number of APIs that have a huge amount of data.\n",
136-
"It is under very active development, so you may see new sources appear.\n",
136+
"Another API example is FRED, the Federal Reserve Economic Data system.\n",
137+
"It's a fairly typical API in that you register for a key, and then you can access the data.\n",
137138
"\n",
138-
"Below, we have a simple example of getting the 10-year US Treasury bond yield at monthly resolution from FRED, the Federal Reserve Economic Data system."
139+
"Let's try a less-guided example of obtaining your API key.\n",
140+
"\n",
141+
"- [FRED API key](https://fred.stlouisfed.org/docs/api/api_key.html)\n",
142+
"- [pyfredapi documentation](https://pyfredapi.readthedocs.io/en/latest/)\n",
143+
"\n",
144+
"Below, we have a simple example of getting the 10-year US Treasury bond yield at monthly resolution from FRED."
139145
]
140146
},
141147
{
@@ -144,10 +150,7 @@
144150
"metadata": {},
145151
"outputs": [],
146152
"source": [
147-
"start = datetime.datetime(2012, 1, 1)\n",
148-
"end = datetime.datetime(2023, 12, 31)\n",
149-
"\n",
150-
"fred_gs10 = pdr.DataReader(\"GS10\", \"fred\", start, end).reset_index()\n",
153+
"fred_gs10 = pf.get_series(\"GS10\")\n",
151154
"fred_gs10.head()"
152155
]
153156
},
@@ -157,7 +160,12 @@
157160
"metadata": {},
158161
"outputs": [],
159162
"source": [
160-
"px.line(fred_gs10, x=\"DATE\", y=\"GS10\", template=\"plotly_dark\").show()"
163+
"px.line(\n",
164+
" fred_gs10[fred_gs10[\"date\"] >= pd.to_datetime(\"2012-01-01\")],\n",
165+
" x=\"date\",\n",
166+
" y=\"value\",\n",
167+
" template=\"plotly_dark\",\n",
168+
").show()"
161169
]
162170
},
163171
{
@@ -166,7 +174,7 @@
166174
"metadata": {},
167175
"outputs": [],
168176
"source": [
169-
"len(fred_gs10)"
177+
"len(fred_gs10[fred_gs10[\"date\"] >= pd.to_datetime(\"2012-01-01\")])"
170178
]
171179
},
172180
{
@@ -207,8 +215,7 @@
207215
"\n",
208216
"If time permits, choose one of the following as a group.\n",
209217
"\n",
210-
"1. Experiment with other searches with the NY Times API by adapting the code above. You may want to create new cells below.\n",
211-
"1. Look at the [pandas-datareader documentation](https://pandas-datareader.readthedocs.io/en/latest/), and decide on another dataset to try out. Like the option above, you may want to create new cells."
218+
"1. Experiment with other searches with the NY Times API by adapting the code above. You may want to create new cells below."
212219
]
213220
}
214221
],
@@ -228,7 +235,7 @@
228235
"name": "python",
229236
"nbconvert_exporter": "python",
230237
"pygments_lexer": "ipython3",
231-
"version": "3.11.4"
238+
"version": "3.12.2"
232239
},
233240
"vscode": {
234241
"interpreter": {

requirements.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
beautifulsoup4==4.12.3
1+
beautifulsoup4==4.13.3
22
geopandas==1.0.1
33
geopy==2.4.1
44
hvplot==0.11.2
55
ipykernel==6.29.5
6-
jupysql==0.10.16
7-
nbconvert==7.16.5
6+
jupysql==0.11.0
7+
nbconvert==7.16.6
88
nbformat==5.10.4
99
notebook==7.3.2
1010
pandas==2.2.3
11-
pandas-datareader==0.10.0
12-
plotly==5.24.1
13-
polars==1.18.0
14-
pre_commit==4.0.1
15-
pyarrow==18.1.0
11+
plotly==6.0.0
12+
polars==1.24.0
13+
pre_commit==4.1.0
14+
pyarrow==19.0.1
15+
pyfredapi==0.9.1
1616
pynytimes==0.10.0
17-
textblob==0.18.0.post0
18-
wrds==3.2.0
17+
textblob==0.19.0
18+
wrds==3.3.0

0 commit comments

Comments
 (0)