Skip to content

Commit

Permalink
Merge 9de403c into 44cadff
Browse files Browse the repository at this point in the history
  • Loading branch information
lnielsen committed Aug 28, 2015
2 parents 44cadff + 9de403c commit 39ece08
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 8 deletions.
13 changes: 13 additions & 0 deletions CHANGES.rst
Expand Up @@ -3,6 +3,19 @@
Changes
=======

0.1.2 (2015-08-28)

* Fixes bug with field names for the FOOD_DES.txt data file.

* Removes field in NUT_DATA.txt which is not included in the SR27
release.

* Fixes bug with CSV delimiter used in Python 2.7.

0.1.1 (2015-08-28)

* Not publicly released.

0.1.0 (2015-08-23)

* Initial public release
14 changes: 12 additions & 2 deletions RELEASE-NOTES.rst
@@ -1,15 +1,25 @@
=========================
Nutrition Parser v0.1.0
Nutrition Parser v0.1.2
=========================

Nutrition Parser v0.1.0 was released on 2015-08-23
Nutrition Parser v0.1.2 was released on 2015-08-28

About
-----

Nutrition Parser is a small package for parsing USDA National Nutrient Database
files.

What's new
----------

* Fixes bug with field names for the FOOD_DES.txt data file.

* Removes field in NUT_DATA.txt which is not included in the SR27
release.

* Fixes bug with CSV delimiter used in Python 2.7.

Installation
------------

Expand Down
2 changes: 1 addition & 1 deletion nutritionparser/__init__.py
Expand Up @@ -84,7 +84,7 @@
NDB_No
FdGrp_Cd
...
FdGrp_Desc
CHO_Factor
Full documentation for each fields is available in the included POF file of the
data.
Expand Down
4 changes: 1 addition & 3 deletions nutritionparser/reader.py
Expand Up @@ -19,7 +19,7 @@

PY2 = sys.version_info[0] == 2

delimiter = '~'.encode('ascii') if PY2 else "^"
delimiter = '^'.encode('ascii') if PY2 else "^"
quotechar = '~'.encode('ascii') if PY2 else '~'


Expand Down Expand Up @@ -73,8 +73,6 @@ def reader(filepath, fields=None):
'Pro_Factor',
'Fat_Factor',
'CHO_Factor',
'FdGrp_Cd',
'FdGrp_Desc',
],
'FD_GROUP.txt': [
'FdGrp_Cd',
Expand Down
2 changes: 1 addition & 1 deletion nutritionparser/version.py
Expand Up @@ -16,4 +16,4 @@
# Do not change the format of this next line. Doing so risks breaking
# setup.py and docs/conf.py

__version__ = "0.1.1.dev20150823"
__version__ = "0.1.3.dev20150828"
101 changes: 101 additions & 0 deletions tests/test_nutritionparser.py
Expand Up @@ -14,6 +14,105 @@

from nutritionparser import reader, sr27fields

first_line_data = {
'FOOD_DES.txt': dict(
NDB_No="01001",
FdGrp_Cd="0100",
Long_Desc="Butter, salted",
Shrt_Desc="BUTTER,WITH SALT",
ComName="",
ManufacName="",
Survey="Y",
Ref_desc="",
Refuse="0",
SciName="",
N_Factor="6.38",
Pro_Factor="4.27",
Fat_Factor="8.79",
CHO_Factor="3.87",
),
'FD_GROUP.txt': dict(
FdGrp_Cd="0100",
FdGrp_Desc="Dairy and Egg Products",
),
'LANGUAL.txt': dict(
NDB_No="02001",
Factor_Code="A0113",
),
'LANGDESC.txt': dict(
Factor_Code="A0107",
Description="BAKERY PRODUCT, UNSWEETENED (US CFR)",
),
'NUT_DATA.txt': dict(
NDB_No="01001",
Nutr_No="203",
Nutr_Val="0.85",
Num_Data_Pts="16",
Std_Error="0.074",
Src_Cd="1",
Deriv_Cd="",
Ref_NDB_No="",
Add_Nutr_Mark="",
Num_Studies="",
Min="",
Max="",
DF="",
Low_EB="",
Up_EB="",
Stat_cmt="",
AddMod_Date="11/1976",
CC="",
),
'NUTR_DEF.txt': dict(
Nutr_No="203",
Units="g",
Tagname="PROCNT",
NutrDesc="Protein",
Num_Dec="2",
SR_Order="600",
),
'SRC_CD.txt': dict(
Src_Cd="1",
SrcCd_Desc="Analytical or derived from analytical",
),
'DERIV_CD.txt': dict(
Deriv_Cd="A",
Deriv_Desc="Analytical data",
),
'WEIGHT.txt': dict(
NDB_No="01001",
Seq="1",
Amount="1",
Msre_Desc="pat (1\" sq, 1/3\" high)",
Gm_Wgt="5.0",
Num_Data_Pts="",
Std_Dev="",
),
'FOOTNOTE.txt': dict(
NDB_No="02009",
Footnt_No="01",
Footnt_Typ="D",
Nutr_No="",
Footnt_Txt="Mix of chili pepper, other spices and salt",
),
'DATSRCLN.txt': dict(
NDB_No="10984",
Nutr_No="518",
DataSrc_ID="S3941",
),
'DATA_SRC.txt': dict(
DataSrc_ID="D1066",
Authors="G.V. Mann",
Title="The Health and Nutritional status of Alaskan Eskimos.",
Year="1962",
Journal="American Journal of Clinical Nutrition",
Vol_City="11",
Issue_State="",
Start_Page="31",
End_Page="76",
),
}


def test_nutritionparser():
"""Test nutritionparser."""
Expand All @@ -23,6 +122,8 @@ def test_nutritionparser():
for f in sr27fields.keys():
for i, data in enumerate(reader("data/{0}".format(f))):
if i == 0:
if f in first_line_data:
assert data == first_line_data[f]
for field in sr27fields[f]:
assert field in data
assert isinstance(data, dict)
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -26,4 +26,4 @@ commands =
{envpython} setup.py clean --all
{envpython} setup.py sdist bdist_wheel build_sphinx
twine upload -r pypi {posargs} dist/*
python setup.py upload_sphinx
python setup.py upload_docs

0 comments on commit 39ece08

Please sign in to comment.