Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend reqs, move to joblib #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

**Version 0.2.3**

* We now use `joblib`'s 'loky' backend for processing the results in parallel. This is related to
[#4](https://github.com/Nelson-Gon/pyfdc/issues/4).

* Tests are now written with the `pytest` framework which means that this is now a dependency. We also now use `pytest_cov` for coverage reports. This also
introduces yet another dependency.

Expand Down
372 changes: 372 additions & 0 deletions example_notebooks/pyfdc_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,372 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"from pyfdc.pyfdc import FoodDataCentral\n",
"from pyfdc.utils import set_api_key\n",
"import os "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pyfdc_key is already a valid key\n"
]
}
],
"source": [
"# This is blank because we already have an environment variable set for the key \n",
"set_api_key()"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"my_search = FoodDataCentral()"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/gonzabat/Desktop/pyfdc/pyfdc/pyfdc.py:112: UserWarning: No target_fields were provided, returning fdc_id, ingredients, and description.\n",
" warn(\"No target_fields were provided, returning fdc_id, ingredients, and description.\")\n"
]
}
],
"source": [
"search = my_search.get_food_info(search_phrase=\"cheese\")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>fdc_id</th>\n",
" <th>ingredients</th>\n",
" <th>description</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1943515</td>\n",
" <td>MILK, SALT, CULTURES, ENZYMES.</td>\n",
" <td>CHEESE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2083541</td>\n",
" <td>PARMESAN AND ROMANO CHEESE. MADE FROM PASTEURI...</td>\n",
" <td>CHEESE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1856944</td>\n",
" <td>BELLAVITANO CHEESE (PASTEURIZED MILK, CHEESE C...</td>\n",
" <td>CHEESE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1867792</td>\n",
" <td>BELLAVITANO CHEESE (PASTEURIZED MILK, CHEESE C...</td>\n",
" <td>CHEESE</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>500370</td>\n",
" <td>GRUYERE CHEESE AND CHEESE (PASTEURIZED MILK, C...</td>\n",
" <td>CHEESE</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" fdc_id ingredients description\n",
"0 1943515 MILK, SALT, CULTURES, ENZYMES. CHEESE\n",
"1 2083541 PARMESAN AND ROMANO CHEESE. MADE FROM PASTEURI... CHEESE\n",
"2 1856944 BELLAVITANO CHEESE (PASTEURIZED MILK, CHEESE C... CHEESE\n",
"3 1867792 BELLAVITANO CHEESE (PASTEURIZED MILK, CHEESE C... CHEESE\n",
"4 500370 GRUYERE CHEESE AND CHEESE (PASTEURIZED MILK, C... CHEESE"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"search.head()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>description</th>\n",
" <th>fdc_id</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>CHEESE</td>\n",
" <td>1943515</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>CHEESE</td>\n",
" <td>2083541</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>CHEESE</td>\n",
" <td>1856944</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>CHEESE</td>\n",
" <td>1867792</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" description fdc_id\n",
"0 CHEESE 1943515\n",
"1 CHEESE 2083541\n",
"2 CHEESE 1856944\n",
"3 CHEESE 1867792"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_search.get_food_info(search_phrase=\"cheese\", target_fields=[\"description\", \"fdc_id\"]).head(4)\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/gonzabat/Desktop/pyfdc/pyfdc/pyfdc.py:162: UserWarning: No target_field was provided, returning low level results.\n",
" warn(\"No target_field was provided, returning low level results.\")\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>0</th>\n",
" <th>1</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>fdcId</td>\n",
" <td>168977</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>description</td>\n",
" <td>Agutuk, meat-caribou (Alaskan ice cream) (Alas...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>publicationDate</td>\n",
" <td>4/1/2019</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>foodNutrients</td>\n",
" <td>[{'nutrient': {'id': 2045, 'number': '951', 'n...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>dataType</td>\n",
" <td>SR Legacy</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>foodClass</td>\n",
" <td>FinalFood</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>nutrientConversionFactors</td>\n",
" <td>[{'id': 17492, 'value': 6.25, 'type': '.Protei...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>ndbNumber</td>\n",
" <td>35003</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>isHistoricalReference</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>foodCategory</td>\n",
" <td>{'id': 24, 'code': '3500', 'description': 'Ame...</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 \\\n",
"0 fdcId \n",
"1 description \n",
"2 publicationDate \n",
"3 foodNutrients \n",
"4 dataType \n",
"5 foodClass \n",
"6 nutrientConversionFactors \n",
"7 ndbNumber \n",
"8 isHistoricalReference \n",
"9 foodCategory \n",
"\n",
" 1 \n",
"0 168977 \n",
"1 Agutuk, meat-caribou (Alaskan ice cream) (Alas... \n",
"2 4/1/2019 \n",
"3 [{'nutrient': {'id': 2045, 'number': '951', 'n... \n",
"4 SR Legacy \n",
"5 FinalFood \n",
"6 [{'id': 17492, 'value': 6.25, 'type': '.Protei... \n",
"7 35003 \n",
"8 True \n",
"9 {'id': 24, 'code': '3500', 'description': 'Ame... "
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"my_search.get_food_details(168977)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.13 ('pyfdc')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "d8711246ff82dafb1ff1fc81455883cb4fae0607334e84927198dc99646575f9"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading