From 93142a1a65296cf1107b9c76a6450a08d5a99de5 Mon Sep 17 00:00:00 2001 From: renae-r Date: Thu, 23 Apr 2026 11:13:06 -0500 Subject: [PATCH 1/3] apply attach_characteristics shoehorn to mtus and ahtus --- src/ipumspy/api/extract.py | 2 +- tests/test_api.py | 41 +++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/ipumspy/api/extract.py b/src/ipumspy/api/extract.py index 2bb7c92..3efdcf0 100644 --- a/src/ipumspy/api/extract.py +++ b/src/ipumspy/api/extract.py @@ -681,7 +681,7 @@ def build(self) -> Dict[str, Any]: } # XXX shoehorn fix until server-side bug is fixed - if self.collection == "meps" or self.collection == "dhs": + if self.collection in ["meps", "dhs", "mtus", "ahtus"]: for variable in built["variables"].keys(): built["variables"][variable].pop("attachedCharacteristics") diff --git a/tests/test_api.py b/tests/test_api.py index b39f1d7..bff8f7e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -158,7 +158,44 @@ def test_usa_build_extract(): "version": None, } - +def test_mtus_build_extract(): + """Make sure unsuported attachCharacteristics elements are removed""" + extract = MicrodataExtract( + collection="mtus", + description="API testing", + samples=["us2023a"], + variables=["SEX","AGE","EMPINCLM","CLOCKST"], + time_use_variables=["ACT_PCARE", "ACT_NOREC"], + data_structure={"hierarchical": {}}, + data_format="fixed_width" + ) + + assert extract.build() == { + 'description': 'API testing', + 'dataFormat': 'fixed_width', + 'dataStructure': {'hierarchical': {}}, + 'samples': {'us2023a': {}}, + 'variables': {'SEX': {'preselected': False, + 'caseSelections': {}, + 'dataQualityFlags': False, + 'adjustMonetaryValues': False}, + 'AGE': {'preselected': False, + 'caseSelections': {}, + 'dataQualityFlags': False, + 'adjustMonetaryValues': False}, + 'EMPINCLM': {'preselected': False, + 'caseSelections': {}, + 'dataQualityFlags': False, + 'adjustMonetaryValues': False}, + 'CLOCKST': {'preselected': False, + 'caseSelections': {}, + 'dataQualityFlags': False, + 'adjustMonetaryValues': False}}, + 'collection': 'mtus', + 'version': None, + 'timeUseVariables': {'ACT_PCARE': {}, 'ACT_NOREC': {}} + } + def test_usa_attach_characteristics(): """ Confirm that attach_characteristics updates extract definition correctly @@ -1893,3 +1930,5 @@ def test_adjust_monetary_values_errors(live_api_client: IpumsApiClient): exc_info.value.args[0] == "Monetary value adjustment is not supported for IPUMS ATUS" ) + + \ No newline at end of file From f87e2ae9764090733cf22d40056e21735c344e55 Mon Sep 17 00:00:00 2001 From: renae-r Date: Thu, 23 Apr 2026 12:21:25 -0500 Subject: [PATCH 2/3] fix rectype hierarchy bug in ddi reader --- src/ipumspy/ddi.py | 18 +- tests/fixtures/atus_00040.xml | 3080 +++++++++++++++++++++++++++++++++ tests/test_ddi.py | 87 +- 3 files changed, 3178 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/atus_00040.xml diff --git a/src/ipumspy/ddi.py b/src/ipumspy/ddi.py index 4a87a4a..11b7ea6 100644 --- a/src/ipumspy/ddi.py +++ b/src/ipumspy/ddi.py @@ -231,9 +231,11 @@ def read(cls, elt: Element, ddi_namespace: str) -> FileDescription: rts = [rectype.attrib["rectype"] for rectype in file_rectypes] except KeyError: rts = [] - # rectype get rectype id var and rectype key var + # (old ddi ordering of record types): rectype get rectype id var and rectype key var # these should be the same across record types for all collections - # so we should be fine to just grab the first appearance of recidvar and keyvar + # so we should be fine to just grab the last appearance of recidvar and keyvar + # (the first appearance now is the top level record type, which does not have + # the keyvar attribute - so now grabbing from the last record type in the hierarchy) try: rectype_idvar = elt.find("./ddi:fileStrc/ddi:recGrp", namespaces).attrib[ "recidvar" @@ -241,9 +243,21 @@ def read(cls, elt: Element, ddi_namespace: str) -> FileDescription: rectype_keyvar = elt.find("./ddi:fileStrc/ddi:recGrp", namespaces).attrib[ "keyvar" ] + # (new ddi ordering of rectypes): if we get a key error, the first appearance now is + # the top level record type, which does not have the keyvar attribute - + # so now grabbing from the last record type in the hierarchy + except KeyError: + rectype_idvar = elt.findall("./ddi:fileStrc/ddi:recGrp", namespaces)[-1].attrib[ + "recidvar" + ] + rectype_keyvar = elt.findall("./ddi:fileStrc/ddi:recGrp", namespaces)[-1].attrib[ + "keyvar" + ] + # if we get an Attribute Error, this is a rectangular file except AttributeError: rectype_idvar = "" rectype_keyvar = "" + return cls( filename=elt.find("./ddi:fileName", namespaces).text, description=elt.find("./ddi:fileCont", namespaces).text, diff --git a/tests/fixtures/atus_00040.xml b/tests/fixtures/atus_00040.xml new file mode 100644 index 0000000..4fc693b --- /dev/null +++ b/tests/fixtures/atus_00040.xml @@ -0,0 +1,3080 @@ + + + + + + + Codebook for an ATUS Data Extract + DDI 2.5 metadata describing the extract file 'atus_00040.dat' + ddi2-27363a39-8e14-11e5-8c97-b82a72e0b782-atus_00040.dat-www.atusdata.org + + + IPUMS + + + IPUMS + April 23, 2026 + IPUMS, 50 Willey Hall, 225 - 19th Avenue South, Minneapolis, MN 55455 + + + IPUMS + + + + + + + User Extract atus_00040.dat + + + IPUMS + + + IPUMS + April 23, 2026 + IPUMS, 50 Willey Hall, 225 - 19th Avenue South, Minneapolis, MN 55455 + + + IPUMS + + + IPUMS ATUS + DOI:10.18128/D060.V3.3 + + + + + + + + Technical Household Variables -- HOUSEHOLD + Technical Person Variables -- PERSON + Weights Variables -- PERSON + Core Demographic Variables -- PERSON + Technical Activity Variables -- ACTIVITY + Technical Who Variables -- WHO + + + 2024 + United States + + + + + + + ATUS + + + The user of the data acknowledges that the original collector of the data, the authorized distributor of the data, and the relevant funding agency bear no responsibility for use of the data or for interpretations or inferences based upon such uses. + + + + + + + atus_00040.dat + Microdata records + + + Household Record + + + Person Record + + + Activity Record + + + Who Record + + + ISO-8859-1 data file + fixed length fields + IPUMS, 50 Willey Hall, 225 - 19th Avenue South, Minneapolis, MN 55455 + + + + + Record Type + + Technical Household Variables -- HOUSEHOLD + + + + + Survey year + + + Technical Household Variables -- HOUSEHOLD + + + + + ATUS Case ID + + + Technical Household Variables -- HOUSEHOLD + + + + + Household serial number + + + Technical Household Variables -- HOUSEHOLD + + + + + Person number (general) + + + 01 + 1 + + + 02 + 2 + + + 03 + 3 + + + 04 + 4 + + + 05 + 5 + + + 06 + 6 + + + 07 + 7 + + + 08 + 8 + + + 09 + 9 + + + 10 + 10 + + + 11 + 11 + + + 12 + 12 + + + 13 + 13 + + + 14 + 14 + + + 15 + 15 + + + 16 + 16 + + Technical Person Variables -- PERSON + + + + + Person line number + + + 001 + 1 + + + 002 + 2 + + + 003 + 3 + + + 004 + 4 + + + 005 + 5 + + + 006 + 6 + + + 007 + 7 + + + 008 + 8 + + + 009 + 9 + + + 010 + 10 + + + 011 + 11 + + + 012 + 12 + + + 013 + 13 + + + 014 + 14 + + + 015 + 15 + + + 016 + 16 + + + 017 + 17 + + + 018 + 18 + + + 019 + 19 + + + 999 + NIU (Not in universe) + + Technical Person Variables -- PERSON + + + + + Person weight, 2006 methodology + + + Weights Variables -- PERSON + + + + + Age + + + Core Demographic Variables -- PERSON + + + + + Sex + + + 01 + Male + + + 02 + Female + + + 99 + NIU (Not in universe) + + Core Demographic Variables -- PERSON + + + + + Activity line number + + + Technical Activity Variables -- ACTIVITY + + + + + Activity + + + 010000 + Personal Care + + + 010100 + Sleeping + + + 010101 + Sleeping + + + 010102 + Sleeplessness + + + 010199 + Sleeping, n.e.c. + + + 010200 + Grooming + + + 010201 + Washing, dressing and grooming oneself + + + 010299 + Grooming, n.e.c. + + + 010300 + Health-Related Self Care + + + 010301 + Health-related self care + + + 010399 + Self care, n.e.c. + + + 010400 + Personal Activities + + + 010401 + Personal/Private activities + + + 010499 + Personal activities, n.e.c. + + + 010500 + Personal Care Emergencies + + + 010501 + Personal emergencies + + + 010599 + Personal care emergencies, n.e.c. + + + 019900 + Personal Care, n.e.c. + + + 019999 + Personal care, n.e.c. + + + 020000 + Household Activities + + + 020100 + Housework + + + 020101 + Interior cleaning + + + 020102 + Laundry + + + 020103 + Sewing, repairing, and maintaining textiles + + + 020104 + Storing interior hh items, inc. food + + + 020199 + Housework, n.e.c. + + + 020200 + Food and Drink Preparation, Presentation, and Clean-up + + + 020201 + Food and drink preparation + + + 020202 + Food presentation + + + 020203 + Kitchen and food clean-up + + + 020299 + Food and drink prep, serving and clean-up, n.e.c. + + + 020300 + Interior Maintenance, Repair, and Decoration + + + 020301 + Interior arrangement, decoration, and repairs + + + 020302 + Building and repairing furniture + + + 020303 + Heating and cooling + + + 020399 + Interior maintenance, repair, and decoration, n.e.c. + + + 020400 + Exterior Maintenance, Repair, and Decoration + + + 020401 + Exterior cleaning + + + 020402 + Exterior repair, improvements, and decoration + + + 020499 + Exterior maintenance, repair and decoration, n.e.c. + + + 020500 + Lawn, Garden, and Houseplants + + + 020501 + Lawn, garden, and houseplant care + + + 020502 + Ponds, pools, and hot tubs + + + 020599 + Lawn and garden, n.e.c. + + + 020600 + Animals and Pets + + + 020601 + Care for animals and pets (not veterinary care) + + + 020602 + Care for animals and pets (not veterinary care) (2008+) + + + 020603 + Walking, exercising, playing with animals (2008+) + + + 020699 + Pet and animal care, n.e.c. + + + 020700 + Vehicles + + + 020701 + Vehicle repair and maintenance (by self) + + + 020799 + Vehicles, n.e.c. + + + 020800 + Appliances, Tools, and Toys + + + 020801 + App, tool, toy set-up, repair, and maint (by self) + + + 020899 + Appliances and tools, n.e.c. + + + 020900 + Household Management + + + 020901 + Financial management + + + 020902 + Household and personal organization and planning + + + 020903 + HH and personal mail and messages (except e-mail) + + + 020904 + HH and personal e-mail and messages + + + 020905 + Home security + + + 020999 + Household management, n.e.c. + + + 029900 + Household Activities, n.e.c. + + + 029999 + Household activities, n.e.c. + + + 030000 + Caring for and Helping Household Members + + + 030100 + Caring for and Helping Household Children + + + 030101 + Physical care for hh children + + + 030102 + Reading to/with hh children + + + 030103 + Playing with hh children, not sports + + + 030104 + Arts and crafts with hh children + + + 030105 + Playing sports with hh children + + + 030106 + Talking with/listening to hh children + + + 030107 + Helping or teaching hh children + + + 030108 + Organization and planning for hh children + + + 030109 + Looking after hh children (as a primary activity) + + + 030110 + Attending hh children's events + + + 030111 + Waiting for/with hh children + + + 030112 + Picking up/dropping off hh children + + + 030199 + Caring for and helping hh children, n.e.c. + + + 030200 + Activities Related to Household Children's Education + + + 030201 + Homework (hh children) + + + 030202 + Meetings and school conferences (hh children) + + + 030203 + Home schooling of hh children + + + 030204 + Waiting associated with hh children's education + + + 030299 + Activities related to hh child's education, n.e.c. + + + 030300 + Activities Related to Household Children's Health + + + 030301 + Providing medical care to hh children + + + 030302 + Obtaining medical care for hh children + + + 030303 + Waiting associated with hh children's health + + + 030399 + Activities related to hh child's health, n.e.c. + + + 030400 + Caring for Household Adults + + + 030401 + Physical care for hh adults + + + 030402 + Looking after hh adult (as a primary activity) + + + 030403 + Providing medical care to hh adult + + + 030404 + Obtaining medical and care services for hh adult + + + 030405 + Waiting associated with caring for hh adults + + + 030499 + Caring for household adults, n.e.c. + + + 030500 + Helping Household Adults + + + 030501 + Helping hh adults + + + 030502 + Organization and planning for hh adults + + + 030503 + Picking up/dropping off hh adult + + + 030504 + Waiting associated with helping hh adults + + + 030599 + Helping household adults, n.e.c. + + + 039900 + Caring for and Helping Household Members, n.e.c. + + + 039999 + Caring for and helping hh members, n.e.c. + + + 040000 + Caring for and Helping Non-Household Members + + + 040100 + Caring for and Helping Non-Household Children + + + 040101 + Physical care for nonhh children + + + 040102 + Reading to/with nonhh children + + + 040103 + Playing with nonhh children, not sports + + + 040104 + Arts and crafts with nonhh children + + + 040105 + Playing sports with nonhh children + + + 040106 + Talking with/listening to nonhh children + + + 040107 + Helping or teaching nonhh children + + + 040108 + Organization and planning for nonhh children + + + 040109 + Looking after nonhh children (as primary activity) + + + 040110 + Attending nonhh children's events + + + 040111 + Waiting for/with nonhh children + + + 040112 + Dropping off/picking up nonhh children + + + 040199 + Caring for and helping nonhh children, n.e.c. + + + 040200 + Activities Related to Non-Household Children's Education + + + 040201 + Homework (nonhh children) + + + 040202 + Mtgs and school conferences (nonhh children) + + + 040203 + Home schooling of nonhh children + + + 040204 + Waiting assoc w/ nonhh children's education + + + 040299 + Activities related to nonhh child's educ., n.e.c. + + + 040300 + Activities Related to Non-Household Children's Health + + + 040301 + Providing medical care to nonhh children + + + 040302 + Obtaining medical care for nonhh children + + + 040303 + Waiting associated with nonhh children's health + + + 040399 + Activities related to nonhh child's health, n.e.c. + + + 040400 + Caring for Non-Household Adults + + + 040401 + Physical care for nonhh adults + + + 040402 + Looking after nonhh adult (as a primary activity) + + + 040403 + Providing medical care to nonhh adult + + + 040404 + Obtaining medical and care svcs for nonhh adult + + + 040405 + Waiting associated with caring for nonhh adults + + + 040499 + Caring for nonhh adults, n.e.c. + + + 040500 + Helping Non-Household Adults + + + 040501 + Hswrk, cooking, and shopping asst, nonhh adults + + + 040502 + House and lawn maint and repair asst, nonhh adults + + + 040503 + Animal and pet care assistance for nonhh adults + + + 040504 + Vehicle/appliance maint/repair asst, nonhh adults + + + 040505 + Financial mgmt asst for nonhh adults + + + 040506 + HH mgmt and paperwork asst, nonhh adults + + + 040507 + Picking up/dropping off nonhh adult + + + 040508 + Waiting associated with helping nonhh adults + + + 040599 + Helping nonhh adults, n.e.c. + + + 049900 + Caring for and Helping Non-Household Members, n.e.c. + + + 049999 + Caring for and helping nonhh members, n.e.c. + + + 050000 + Work and Work-Related Activities + + + 050100 + Working + + + 050101 + Work, main job + + + 050102 + Work, other job(s) + + + 050103 + Security procedures related to work + + + 050104 + Waiting associated with working + + + 050199 + Working, n.e.c. + + + 050200 + Work-Related Activities + + + 050201 + Socializing, relaxing, and leisure as part of job + + + 050202 + Eating and drinking as part of job + + + 050203 + Sports and exercise as part of job + + + 050204 + Security procedures as part of job + + + 050205 + Waiting associated with work-related activities + + + 050299 + Work-related activities, n.e.c. + + + 050300 + Other Income-Generating Activities + + + 050301 + Income-generating hobbies, crafts, and food + + + 050302 + Income-generating performances + + + 050303 + Income-generating services + + + 050304 + Income-generating rental property activities + + + 050305 + Waiting assoc w/other income-generating acts + + + 050399 + Other income-generating activities, n.e.c. + + + 050400 + Job Search and Interviewing + + + 050401 + Job search activities + + + 050403 + Job interviewing + + + 050404 + Waiting associated with job search or interview + + + 050405 + Sec. procedures rel. to job search/interviewing + + + 050499 + Job search and Interviewing, n.e.c. + + + 059900 + Work and Work-Related Activities, n.e.c. + + + 059999 + Work and work-related activities, n.e.c. + + + 060000 + Education + + + 060100 + Taking Class + + + 060101 + Taking class for degree, certification, or lic + + + 060102 + Taking class for personal interest + + + 060103 + Waiting associated with taking classes + + + 060104 + Security procedures rel. to taking classes + + + 060199 + Taking class, n.e.c. + + + 060200 + Extracurricular School Activities (except sports) + + + 060201 + Extracurricular club activities + + + 060202 + Extracurricular music and performance activities + + + 060203 + Extracurricular student government activities + + + 060204 + Waiting associated with extracurricular activities + + + 060299 + Education-related extracurricular activities, n.e.c. + + + 060300 + Research or Homework + + + 060301 + Rsrch/HW for class for degree, cert, or lic + + + 060302 + Research/homework for class for pers. interest + + + 060303 + Waiting associated with research/homework + + + 060399 + Research/homework n.e.c. + + + 060400 + Registration or Administrative Activities + + + 060401 + Admin activities: class for degree, cert, or lic + + + 060402 + Admin activities: class for personal interest + + + 060403 + Waiting assoc w/admin. activities (education) + + + 060499 + Administrative for education, n.e.c. + + + 069900 + Education, n.e.c. + + + 069999 + Education, n.e.c. + + + 070000 + Consumer Purchases + + + 070100 + Shopping (store, telephone, internet) + + + 070101 + Grocery shopping + + + 070102 + Purchasing gas + + + 070103 + Purchasing food (not groceries) + + + 070104 + Shopping, except groceries, food and gas + + + 070105 + Waiting associated with shopping + + + 070199 + Shopping, n.e.c. + + + 070200 + Researching Purchases + + + 070201 + Comparison shopping + + + 070299 + Researching purchases, n.e.c. + + + 070300 + Security Procedures Related to Consumer Purchases + + + 070301 + Security procedures rel. to consumer purchases + + + 070399 + Sec procedures rel. to cons purchases, n.e.c. + + + 079900 + Consumer Purchases, n.e.c. + + + 079999 + Consumer purchases, n.e.c. + + + 080000 + Professional and Personal Care Services + + + 080100 + Childcare Services + + + 080101 + Using paid childcare services + + + 080102 + Waiting associated w/purchasing childcare svcs + + + 080199 + Using paid childcare services, n.e.c. + + + 080200 + Financial Services and Banking + + + 080201 + Banking + + + 080202 + Using other financial services + + + 080203 + Waiting associated w/banking/financial services + + + 080299 + Using financial services and banking, n.e.c. + + + 080300 + Legal Services + + + 080301 + Using legal services + + + 080302 + Waiting associated with legal services + + + 080399 + Using legal services, n.e.c. + + + 080400 + Medical and Care Services + + + 080401 + Using health and care services outside the home + + + 080402 + Using in-home health and care services + + + 080403 + Waiting associated with medical services + + + 080499 + Using medical services, n.e.c. + + + 080500 + Personal Care Services + + + 080501 + Using personal care services + + + 080502 + Waiting associated w/personal care services + + + 080599 + Using personal care services, n.e.c. + + + 080600 + Real Estate + + + 080601 + Activities rel. to purchasing/selling real estate + + + 080602 + Waiting assoc w/purchasing/selling real estate + + + 080699 + Using real estate services, n.e.c. + + + 080700 + Veterinary Services (excluding grooming) + + + 080701 + Using veterinary services + + + 080702 + Waiting associated with veterinary services + + + 080799 + Using veterinary services, n.e.c. + + + 080800 + Security Procedures Related to Professional or Personal Services + + + 080801 + Security procedures rel. to prof/personal svcs. + + + 080899 + Sec procedures rel. to prof/personal svcs n.e.c. + + + 089900 + Professional and Personal Services, n.e.c. + + + 089999 + Professional and personal services, n.e.c. + + + 090000 + Household Services + + + 090100 + Household Services (not done by self) + + + 090101 + Using interior cleaning services + + + 090102 + Using meal preparation services + + + 090103 + Using clothing repair and cleaning services + + + 090104 + Waiting associated with using household services + + + 090199 + Using household services, n.e.c. + + + 090200 + Home Maintenance, Repair, Decoration, and Construction (not done by self) + + + 090201 + Using home maint/repair/décor/construction svcs + + + 090202 + Wtg assoc w/ home main/repair/décor/constr + + + 090299 + Using home maint/repair/décor/constr svcs n.e.c. + + + 090300 + Pet Services (not done by self and not veterinary care) + + + 090301 + Using pet services + + + 090302 + Waiting associated with pet services + + + 090399 + Using pet services, n.e.c. + + + 090400 + Lawn and Garden Services (not done by self) + + + 090401 + Using lawn and garden services + + + 090402 + Waiting assoc with using lawn and garden svcs + + + 090499 + Using lawn and garden services, n.e.c. + + + 090500 + Vehicle Maintenance and Repair Services (not done by self) + + + 090501 + Using vehicle maintenance or repair services + + + 090502 + Waiting assoc with vehicle main. or repair svcs + + + 090599 + Using vehicle maint. and repair svcs, n.e.c. + + + 099900 + Household Services, n.e.c. + + + 099999 + Using household services, n.e.c. + + + 100000 + Government Services and Civic Obligations + + + 100100 + Using Government Services + + + 100101 + Using police and fire services + + + 100102 + Using social services + + + 100103 + Obtaining licenses and paying fines, fees, taxes + + + 100199 + Using government services, n.e.c. + + + 100200 + Civic Obligations and Participation + + + 100201 + Civic obligations and participation + + + 100299 + Civic obligations and participation, n.e.c. + + + 100300 + Waiting Associated with Government Services or Civic Obligations + + + 100303 + Waiting assoc w/civic obligations and participation + + + 100304 + Waiting associated with using government services + + + 100399 + Wtg assoc w/govt svcs or civic obligations, n.e.c. + + + 100400 + Security Procedures Related to Government Services or Civic Obligations + + + 100401 + Sec procedures rel. to govt svcs/civic obligations + + + 100499 + Sec procs rel. to govt svcs/civic obligations, n.e.c. + + + 109900 + Government Services, n.e.c. + + + 109999 + Government services, n.e.c. + + + 110000 + Eating and Drinking + + + 110100 + Eating and Drinking + + + 110101 + Eating and drinking + + + 110199 + Eating and drinking, n.e.c. + + + 110200 + Waiting Associated with Eating and Drinking + + + 110201 + Waiting associated w/eating and drinking + + + 110299 + Waiting associated with eating and drinking, n.e.c. + + + 119900 + Eating and Drinking, n.e.c. + + + 119999 + Eating and drinking, n.e.c. + + + 120000 + Socializing, Relaxing, and Leisure + + + 120100 + Socializing and Communicating + + + 120101 + Socializing and communicating with others + + + 120199 + Socializing and communicating, n.e.c. + + + 120200 + Attending or Hosting Social Events + + + 120201 + Attending or hosting parties/receptions/ceremonies + + + 120202 + Attending meetings for personal interest (not volunteering) + + + 120299 + Attending/hosting social events, n.e.c. + + + 120300 + Relaxing and Leisure + + + 120301 + Relaxing, thinking + + + 120302 + Tobacco and drug use + + + 120303 + Television and movies (not religious) + + + 120304 + Television (religious) + + + 120305 + Listening to the radio + + + 120306 + Listening to/playing music (not radio) + + + 120307 + Playing games + + + 120308 + Computer use for leisure (exc. Games) + + + 120309 + Arts and crafts as a hobby + + + 120310 + Collecting as a hobby + + + 120311 + Hobbies, except arts and crafts and collecting + + + 120312 + Reading for personal interest + + + 120313 + Writing for personal interest + + + 120399 + Relaxing and leisure, n.e.c. + + + 120400 + Arts and Entertainment (other than sports) + + + 120401 + Attending performing arts + + + 120402 + Attending museums + + + 120403 + Attending movies/film + + + 120404 + Attending gambling establishments + + + 120405 + Security procedures rel. to arts and entertainment + + + 120499 + Arts and entertainment, n.e.c. + + + 120500 + Waiting Associated with Socializing, Relaxing, and Leisure + + + 120501 + Waiting assoc. w/socializing and communicating + + + 120502 + Waiting assoc. w/attending/hosting social events + + + 120503 + Waiting associated with relaxing/leisure + + + 120504 + Waiting associated with arts and entertainment + + + 120599 + Waiting associated with socializing, n.e.c. + + + 129900 + Socializing, Relaxing, and Leisure, n.e.c. + + + 129999 + Socializing, relaxing, and leisure, n.e.c. + + + 130000 + Sports, Exercise, and Recreation + + + 130100 + Participating in Sports, Exercise, or Recreation + + + 130101 + Doing aerobics + + + 130102 + Playing baseball + + + 130103 + Playing basketball + + + 130104 + Biking + + + 130105 + Playing billiards + + + 130106 + Boating + + + 130107 + Bowling + + + 130108 + Climbing, spelunking, caving + + + 130109 + Dancing + + + 130110 + Participating in equestrian sports + + + 130111 + Fencing + + + 130112 + Fishing + + + 130113 + Playing football + + + 130114 + Golfing + + + 130115 + Doing gymnastics + + + 130116 + Hiking + + + 130117 + Playing hockey + + + 130118 + Hunting + + + 130119 + Participating in martial arts + + + 130120 + Playing racquet sports + + + 130121 + Participating in rodeo competitions + + + 130122 + Rollerblading + + + 130123 + Playing rugby + + + 130124 + Running + + + 130125 + Skiing, ice skating, snowboarding + + + 130126 + Playing soccer + + + 130127 + Playing softball + + + 130128 + Using cardiovascular equipment + + + 130129 + Vehicle touring/racing + + + 130130 + Playing volleyball + + + 130131 + Walking + + + 130132 + Participating in water sports + + + 130133 + Weightlifting/strength training + + + 130134 + Working out, unspecified + + + 130135 + Wrestling + + + 130136 + Doing yoga + + + 130199 + Playing sports n.e.c. + + + 130200 + Attending Sports or Recreational Events + + + 130201 + Watching aerobics + + + 130202 + Watching baseball + + + 130203 + Watching basketball + + + 130204 + Watching biking + + + 130205 + Watching billiards + + + 130206 + Watching boating + + + 130207 + Watching bowling + + + 130208 + Watching climbing, spelunking, caving + + + 130209 + Watching dancing + + + 130210 + Watching equestrian sports + + + 130211 + Watching fencing + + + 130212 + Watching fishing + + + 130213 + Watching football + + + 130214 + Watching golfing + + + 130215 + Watching gymnastics + + + 130216 + Watching hockey + + + 130217 + Watching martial arts + + + 130218 + Watching racquet sports + + + 130219 + Watching rodeo competitions + + + 130220 + Watching rollerblading + + + 130221 + Watching rugby + + + 130222 + Watching running + + + 130223 + Watching skiing, ice skating, snowboarding + + + 130224 + Watching soccer + + + 130225 + Watching softball + + + 130226 + Watching vehicle touring/racing + + + 130227 + Watching volleyball + + + 130228 + Watching walking + + + 130229 + Watching water sports + + + 130230 + Watching weightlifting/strength training + + + 130231 + Watching people working out, unspecified + + + 130232 + Watching wrestling + + + 130299 + Attending sporting events, n.e.c. + + + 130300 + Waiting Associated with Sports, Exercise, and Recreation + + + 130301 + Waiting related to playing sports or exercising + + + 130302 + Waiting related to attending sporting events + + + 130399 + Wtg assoc with sports, exercise, and rec, n.e.c. + + + 130400 + Security Procedures Related to Sports, Exercise, and Recreation + + + 130401 + Security related to playing sports or exercising + + + 130402 + Security related to attending sporting events + + + 130499 + Sec related to sports, exercise, and rec, n.e.c. + + + 139900 + Sports, Exercise, and Recreation, n.e.c. + + + 139999 + Sports, exercise, and recreation, n.e.c. + + + 140000 + Religious and Spiritual Activities + + + 140100 + Religious or Spiritual Practices + + + 140101 + Attending religious services + + + 140102 + Participation in religious practices + + + 140103 + Waiting assoc w/religious and spiritual activities + + + 140104 + Sec procedures rel. to relig and spiritual activities + + + 140105 + Religious education activities (2007+) + + + 149900 + Religious and Spiritual Activities, n.e.c. + + + 149999 + Religious and spiritual activities, n.e.c. + + + 150000 + Volunteer Activities + + + 150100 + Administrative and Support Activities + + + 150101 + Computer use + + + 150102 + Organizing and preparing + + + 150103 + Reading + + + 150104 + Telephone calls (except hotline counseling) + + + 150105 + Writing + + + 150106 + Fundraising + + + 150199 + Administrative and support activities, n.e.c. + + + 150200 + Social Service and Care Activities (except medical) + + + 150201 + Food preparation, presentation, clean-up + + + 150202 + Collecting and delivering clothing and other goods + + + 150203 + Providing care + + + 150204 + Teaching, leading, counseling, mentoring + + + 150299 + Social service and care activities, n.e.c. + + + 150300 + Indoor and Outdoor Maintenance, Building, and Clean-Up Activities + + + 150301 + Building houses, wildlife sites, and other structures + + + 150302 + Indoor and outdoor maintenance, repair, and clean-up + + + 150399 + Indoor and outdoor maint, bldg and clean-up, n.e.c. + + + 150400 + Participating in Performance and Cultural Activities + + + 150401 + Performing + + + 150402 + Serving at volunteer events and cultural activities + + + 150499 + Participating performance, cultural act., n.e.c. + + + 150500 + Attending Meetings, Conferences, and Training + + + 150501 + Attending meetings, conferences, and training + + + 150599 + Attending mtgs conferences, and training, n.e.c. + + + 150600 + Public Health and Safety Activities + + + 150601 + Public health activities + + + 150602 + Public safety activities + + + 150699 + Public health and safety activities, n.e.c. + + + 150700 + Waiting Associated with Volunteer Activities + + + 150701 + Waiting associated with volunteer activities + + + 150799 + Waiting assoc with volunteer activities, n.e.c. + + + 150800 + Security Procedures Related to Volunteer Activities + + + 150801 + Security procedures related to volunteer activities (2007+) + + + 150899 + Security proecdures related to voluteer activities, n.e.c. (2007+) + + + 159900 + Volunteer Activities, n.e.c. + + + 159999 + Volunteer activities, n.e.c. + + + 160000 + Telephone Calls + + + 160100 + Telephone Calls (to or from) + + + 160101 + Telephone calls to/from family members + + + 160102 + Phone calls to/from friends, neighbors + + + 160103 + Telephone calls to/from education svcs providers + + + 160104 + Telephone calls to/from salespeople + + + 160105 + Phone calls to/from prof, personal svcs providers + + + 160106 + Phone calls to/from household services providers + + + 160107 + Phone calls to/from child or adult care providers + + + 160108 + Telephone calls to/from government officials + + + 160199 + Telephone calls (to or from), n.e.c. + + + 160200 + Waiting Associated with Telephone Calls + + + 160201 + Waiting associated with telephone calls + + + 160299 + Waiting associated with telephone calls, n.e.c. + + + 169900 + Telephone Calls, n.e.c. + + + 169999 + Telephone calls, n.e.c. + + + 180000 + Traveling + + + 180100 + Travel Related to Personal Care + + + 180101 + Travel related to personal care + + + 180199 + Travel related to personal care, n.e.c. + + + 180200 + Travel Related to Household Activities + + + 180201 + Travel related to housework + + + 180202 + Travel related to food and drink prep + + + 180203 + Travel related to int. maint, repair, and decoration + + + 180204 + Travel related to ext. maint, repair, and decoration + + + 180205 + Travel related to lawn, garden, and houseplants + + + 180206 + Travel related to care for animals (not vet care) + + + 180207 + Travel related to vehicle care and maint (by self) + + + 180208 + Trvl rel to app, tool, toy set-up, repair, and maint + + + 180209 + Travel related to household management + + + 180299 + Travel related to household activities, n.e.c. + + + 180300 + Travel Related to Caring for and Helping Household Members + + + 180301 + Travel related to caring for and helping HH children + + + 180302 + Travel related to caring for and helping household children (2005+) + + + 180303 + Travel related to hh children's education + + + 180304 + Travel related to hh children's health + + + 180305 + Travel related to caring for hh adults + + + 180306 + Travel related to helping hh adults + + + 180307 + Travel related to caring for and helping HH adults + + + 180399 + Trvl rel. to caring for, helping HH members, n.e.c. + + + 180400 + Travel Related to Caring for and Helping Non-Household Members + + + 180401 + Trvl rel to caring for and helping nonHH kids, inclusive + + + 180402 + Trvl rel to caring for and helping nonHH kids + + + 180403 + Travel related to nonhh children's education + + + 180404 + Travel related to nonhh children's health + + + 180405 + Travel related to caring for nonhh adults + + + 180406 + Travel related to helping nonhh adults + + + 180407 + Travel related to caring for, helping NonHH adults + + + 180499 + Trvl rel. to caring for, helping NonHH, n.e.c. + + + 180500 + Travel Related to Work + + + 180501 + Travel related to working + + + 180502 + Travel related to work-related activities + + + 180503 + Travel related to income-generating activities + + + 180504 + Travel related to job search and interviewing + + + 180599 + Travel related to work, n.e.c. + + + 180600 + Travel Related to Education + + + 180601 + Travel related to taking class + + + 180602 + Trvl rel to extracurricular activities (ex. Sports) + + + 180603 + Travel related to research/homework + + + 180604 + Travel related to registration/admin activities + + + 180605 + Education-related travel, not commuting + + + 180699 + Education travel, n.e.c. + + + 180700 + Travel Related to Consumer Purchases + + + 180701 + Traveling to/from the grocery store + + + 180702 + Travel related to other shopping + + + 180703 + Travel related to purchasing food (not groceries) + + + 180704 + Travel related to shopping, ex groc, food, gas + + + 180705 + Traveling to/from gas station + + + 180799 + Travel related to consumer purchases, n.e.c. + + + 180800 + Travel Related to Using Professional and Personal Care Services + + + 180801 + Travel related to using childcare services + + + 180802 + Travel related to using financial svcs and banking + + + 180803 + Travel related to using legal services + + + 180804 + Travel related to using medical services + + + 180805 + Travel related to using personal care services + + + 180806 + Travel related to using real estate services + + + 180807 + Travel related to using veterinary services + + + 180899 + Travel rel. to using prof, personal care svcs n.e.c. + + + 180900 + Travel Related to Using Household Services + + + 180901 + Travel related to using household services + + + 180902 + Trvl rel to using home maint etc svcs + + + 180903 + Travel related to using pet services (not vet) + + + 180904 + Travel related to using lawn and garden services + + + 180905 + Trvl rel to using vehicle maint and repair services + + + 180999 + Travel related to using household services, n.e.c. + + + 181000 + Travel Related to Using Government Services and Civic Obligations + + + 181001 + Travel related to using government services + + + 181002 + Travel related to civic obligations and participation + + + 181099 + Travel rel. to govt svcs and civic obligations, n.e.c. + + + 181100 + Travel Related to Eating and Drinking + + + 181101 + Travel related to eating and drinking + + + 181199 + Travel related to eating and drinking, n.e.c. + + + 181200 + Travel Related to Socializing, Relaxing, and Leisure + + + 181201 + Travel related to socializing and communicating + + + 181202 + Trvl related to attending or hosting social events + + + 181203 + Travel related to relaxing and leisure (2003, 2004) + + + 181204 + Travel related to arts and entertainment + + + 181205 + Travel as a form of entertainment + + + 181206 + Travel related to relaxing and leisure (2005+) + + + 181299 + Travel rel. to socializing, relaxing, leisure, n.e.c. + + + 181300 + Travel Related to Sports, Exercise, and Recreation + + + 181301 + Trvl rel to doing sports/exercise/recreation + + + 181302 + Trvl rel to attending sporting/recreational events + + + 181399 + Travel rel to sports, exercise, recreation, n.e.c. + + + 181400 + Travel Related to Religious or Spiritual Activities + + + 181401 + Travel related to religious/spiritual practices + + + 181499 + Travel rel. to religious/spiritual activities, n.e.c. + + + 181500 + Travel Related to Volunteering + + + 181501 + Travel related to volunteering + + + 181599 + Travel related to volunteer activities, n.e.c. + + + 181600 + Travel Related to Phone Calls + + + 181601 + Travel related to phone calls + + + 181699 + Travel rel. to phone calls, n.e.c. + + + 181800 + Security Procedures Related to Traveling + + + 181801 + Security procedures related to traveling + + + 181899 + Security procedures related to traveling, n.e.c. + + + 189900 + Traveling, n.e.c. + + + 189999 + Traveling, n.e.c. + + + 500000 + Data Codes + + + 500100 + Unable to Code + + + 500101 + Insufficient detail in verbatim + + + 500102 + Recorded activity using incorrect words + + + 500103 + Missing travel or destination + + + 500104 + Recorded simultaneous activities incorrectly + + + 500105 + Respondent refused to provide information + + + 500106 + Gap/can't remember + + + 500107 + Unable to code activity at 1st tier + + + 509900 + Data codes, n.e.c. + + + 509999 + Data codes, n.e.c. + + Technical Activity Variables -- ACTIVITY + + + + + Location of activity + + + 0100 + Place + + + 0101 + R's home or yard + + + 0102 + R's workplace + + + 0103 + Someone else's home + + + 0104 + Restaurant or bar + + + 0105 + Place of worship + + + 0106 + Grocery store + + + 0107 + Other store/mall + + + 0108 + School + + + 0109 + Outdoors--not at home + + + 0110 + Library + + + 0111 + Bank + + + 0112 + Gym/health club + + + 0113 + Post Office + + + 0114 + Other place + + + 0115 + Unspecified place + + + 0200 + Mode of Transportation + + + 0230 + Driver of car, truck, or motorcycle + + + 0231 + Passenger of car, truck, or motorcycle + + + 0232 + Walking + + + 0233 + Bus + + + 0234 + Subway/train + + + 0235 + Bicycle + + + 0236 + Boat/ferry + + + 0237 + Taxi/limousine service + + + 0238 + Airplane + + + 0239 + Other mode of transportation + + + 0240 + Unspecified mode of transportation + + + 9997 + Don't know + + + 9998 + Refused + + + 9999 + NIU (Not in universe) + + Technical Activity Variables -- ACTIVITY + + + + + Activity line number + + + Technical Who Variables -- WHO + + + + + Relationship of person with whom activity was done + + + 0100 + Alone + + + 0200 + Spouse + + + 0201 + Unmarried partner + + + 0202 + Own household child + + + 0203 + Grandchild + + + 0204 + Parent + + + 0205 + Brother sister + + + 0206 + Other related person + + + 0207 + Foster child + + + 0208 + Housemate, roommate + + + 0209 + Roomer, boarder + + + 0210 + Other nonrelative + + + 0300 + Own non-household child under 18 + + + 0400 + Parents (not living in household) + + + 0401 + Other non-household family members under 18 + + + 0402 + Other non-household family members 18 and older (including parents-in-law) + + + 0403 + Friends + + + 0404 + Co-workers, colleagues, clients (non-work activities only) + + + 0405 + Neighbors, acquaintances + + + 0406 + Other non-household children under 18 + + + 0407 + Other non-household adults 18 and older + + + 0408 + Boss or manager (work activities only, 2010+) + + + 0409 + People whom I supervise (work activities only, 2010+) + + + 0410 + Co-workers (work activities only, 2010+) + + + 0411 + Customers (work activities only, 2010+) + + + 9996 + Refused + + + 9997 + Don't know + + + 9998 + Blank + + Technical Who Variables -- WHO + + + + diff --git a/tests/test_ddi.py b/tests/test_ddi.py index e0312f4..8f25bfe 100644 --- a/tests/test_ddi.py +++ b/tests/test_ddi.py @@ -32,10 +32,10 @@ def cps_ddi_hierarchical(fixtures_path: Path) -> ddi.Codebook: return readers.read_ipums_ddi(fixtures_path / "cps_00421.xml") -# not implemented yet -# @pytest.fixture(scope="function") -# def cps_df_hierarchical(fixtures_path: Path, cps_ddi_hierarchical: ddi.Codebook) -> pd.DataFrame: -# return readers.read_microdata(cps_ddi_hierarchical, fixtures_path / "cps_00421.dat.gz") +@pytest.fixture(scope="function") +def atus_ddi_hierarchical(fixtures_path: Path) -> ddi.Codebook: + """DDI with rectypes in order of hierarchy""" + return readers.read_ipums_ddi(fixtures_path / "atus_00040.xml") def test_get_variable_info_rectangular(cps_ddi: ddi.Codebook): @@ -116,7 +116,7 @@ def test_get_variable_info_hierarchical(cps_ddi_hierarchical: ddi.Codebook): # And does it raise a ValueError if the variable does not exist? with pytest.raises(ValueError): cps_ddi_hierarchical.get_variable_info("foo") - + def test_ddi_codebook_rectangular(cps_ddi: ddi.Codebook): # sample descriptions/names @@ -274,6 +274,83 @@ def test_ddi_codebook_hierarchical(cps_ddi_hierarchical: ddi.Codebook): "\n" "(4) Use it for GOOD -- never for EVIL." ) + + +def test_complex_ddi_codebook_hierarchical(atus_ddi_hierarchical: ddi.Codebook): + """Test ddi with more than two record types""" + # sample descriptions/names + assert atus_ddi_hierarchical.samples_description == [ + "ATUS 2024" + ] + + # doi + assert atus_ddi_hierarchical.ipums_doi == "DOI:10.18128/D060.V3.3" + + # data format + assert atus_ddi_hierarchical.file_description.format == "fixed length fields" + + # data structure + assert atus_ddi_hierarchical.file_description.structure == "hierarchical" + + # rectypes + assert atus_ddi_hierarchical.file_description.rectypes == ['1', '2', '3', '4'] + + # rectype idvar + assert atus_ddi_hierarchical.file_description.rectype_idvar == "RECTYPE" + + # rectype keyvar + assert atus_ddi_hierarchical.file_description.rectype_keyvar == "CASEID" + + # data collection + assert atus_ddi_hierarchical.ipums_collection == "atus" + + # citation + assert atus_ddi_hierarchical.ipums_citation == ( + "Publications and research reports based on the " + "ATUS database must cite it appropriately. " + "The citation should include the following:\n" + "\n" + "Sarah M. Flood, Liana C. Sayer, and Daniel Backman. " + "American Time Use Survey Data Extract Builder: Version 3.3 [dataset]. " + "College Park, MD: University of Maryland and Minneapolis, MN: IPUMS, 2025. " + "https://doi.org/10.18128/D060.V3.3\n" + "\n" + "The licensing agreement for use of ATUS " + "data requires that users supply us with the " + "title and full citation for any publications, " + "research reports, or educational materials " + "making use of the data or documentation. Please " + "add your citation to the IPUMS bibliography: " + "http://bibliography.ipums.org/" + ) + + # terms of use + assert atus_ddi_hierarchical.ipums_conditions == ( + "Users of ATUS data must agree to abide by " + "the conditions of use. A user's license is " + "valid for one year and may be renewed. Users " + "must agree to the following conditions:\n" + "\n" + "(1) No fees may be charged for use or " + "distribution of the data. All persons are " + "granted a limited license to use these data, " + "but you may not charge a fee for the data if " + "you distribute it to others.\n" + "\n" + "(2) Cite IPUMS appropriately. For information " + "on proper citation, refer to the citation " + "requirement section of this DDI document.\n" + "\n" + "(3) Tell us about any work you do using the " + "IPUMS. Publications, research reports, or " + "presentations making use of ATUS should " + "be added to our Bibliography. Continued " + "funding for the IPUMS depends on our ability " + "to show our sponsor agencies that researchers " + "are using the data for productive purposes.\n" + "\n" + "(4) Use it for GOOD -- never for EVIL." + ) def test_get_all_types(cps_ddi: ddi.Codebook, cps_df: pd.DataFrame): From d1f4e45e06c26784d2271e74489813d6d63643a2 Mon Sep 17 00:00:00 2001 From: renae-r Date: Thu, 23 Apr 2026 12:22:47 -0500 Subject: [PATCH 3/3] version bump, :black_heart: --- pyproject.toml | 2 +- src/ipumspy/ddi.py | 18 ++++++------ tests/test_api.py | 68 ++++++++++++++++++++++++++-------------------- tests/test_ddi.py | 12 ++++---- 4 files changed, 54 insertions(+), 46 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 95a7894..384e5a4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ipumspy" -version = "0.8.0" +version = "0.8.1" description = "A collection of tools for working with IPUMS data" authors = ["Kevin H. Wilson ", "Renae Rodgers "] diff --git a/src/ipumspy/ddi.py b/src/ipumspy/ddi.py index 11b7ea6..aa81c07 100644 --- a/src/ipumspy/ddi.py +++ b/src/ipumspy/ddi.py @@ -243,21 +243,21 @@ def read(cls, elt: Element, ddi_namespace: str) -> FileDescription: rectype_keyvar = elt.find("./ddi:fileStrc/ddi:recGrp", namespaces).attrib[ "keyvar" ] - # (new ddi ordering of rectypes): if we get a key error, the first appearance now is - # the top level record type, which does not have the keyvar attribute - + # (new ddi ordering of rectypes): if we get a key error, the first appearance now is + # the top level record type, which does not have the keyvar attribute - # so now grabbing from the last record type in the hierarchy except KeyError: - rectype_idvar = elt.findall("./ddi:fileStrc/ddi:recGrp", namespaces)[-1].attrib[ - "recidvar" - ] - rectype_keyvar = elt.findall("./ddi:fileStrc/ddi:recGrp", namespaces)[-1].attrib[ - "keyvar" - ] + rectype_idvar = elt.findall("./ddi:fileStrc/ddi:recGrp", namespaces)[ + -1 + ].attrib["recidvar"] + rectype_keyvar = elt.findall("./ddi:fileStrc/ddi:recGrp", namespaces)[ + -1 + ].attrib["keyvar"] # if we get an Attribute Error, this is a rectangular file except AttributeError: rectype_idvar = "" rectype_keyvar = "" - + return cls( filename=elt.find("./ddi:fileName", namespaces).text, description=elt.find("./ddi:fileCont", namespaces).text, diff --git a/tests/test_api.py b/tests/test_api.py index bff8f7e..d0774b8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -158,44 +158,56 @@ def test_usa_build_extract(): "version": None, } + def test_mtus_build_extract(): """Make sure unsuported attachCharacteristics elements are removed""" extract = MicrodataExtract( collection="mtus", description="API testing", samples=["us2023a"], - variables=["SEX","AGE","EMPINCLM","CLOCKST"], + variables=["SEX", "AGE", "EMPINCLM", "CLOCKST"], time_use_variables=["ACT_PCARE", "ACT_NOREC"], data_structure={"hierarchical": {}}, - data_format="fixed_width" + data_format="fixed_width", ) - + assert extract.build() == { - 'description': 'API testing', - 'dataFormat': 'fixed_width', - 'dataStructure': {'hierarchical': {}}, - 'samples': {'us2023a': {}}, - 'variables': {'SEX': {'preselected': False, - 'caseSelections': {}, - 'dataQualityFlags': False, - 'adjustMonetaryValues': False}, - 'AGE': {'preselected': False, - 'caseSelections': {}, - 'dataQualityFlags': False, - 'adjustMonetaryValues': False}, - 'EMPINCLM': {'preselected': False, - 'caseSelections': {}, - 'dataQualityFlags': False, - 'adjustMonetaryValues': False}, - 'CLOCKST': {'preselected': False, - 'caseSelections': {}, - 'dataQualityFlags': False, - 'adjustMonetaryValues': False}}, - 'collection': 'mtus', - 'version': None, - 'timeUseVariables': {'ACT_PCARE': {}, 'ACT_NOREC': {}} + "description": "API testing", + "dataFormat": "fixed_width", + "dataStructure": {"hierarchical": {}}, + "samples": {"us2023a": {}}, + "variables": { + "SEX": { + "preselected": False, + "caseSelections": {}, + "dataQualityFlags": False, + "adjustMonetaryValues": False, + }, + "AGE": { + "preselected": False, + "caseSelections": {}, + "dataQualityFlags": False, + "adjustMonetaryValues": False, + }, + "EMPINCLM": { + "preselected": False, + "caseSelections": {}, + "dataQualityFlags": False, + "adjustMonetaryValues": False, + }, + "CLOCKST": { + "preselected": False, + "caseSelections": {}, + "dataQualityFlags": False, + "adjustMonetaryValues": False, + }, + }, + "collection": "mtus", + "version": None, + "timeUseVariables": {"ACT_PCARE": {}, "ACT_NOREC": {}}, } - + + def test_usa_attach_characteristics(): """ Confirm that attach_characteristics updates extract definition correctly @@ -1930,5 +1942,3 @@ def test_adjust_monetary_values_errors(live_api_client: IpumsApiClient): exc_info.value.args[0] == "Monetary value adjustment is not supported for IPUMS ATUS" ) - - \ No newline at end of file diff --git a/tests/test_ddi.py b/tests/test_ddi.py index 8f25bfe..095c7e1 100644 --- a/tests/test_ddi.py +++ b/tests/test_ddi.py @@ -116,7 +116,7 @@ def test_get_variable_info_hierarchical(cps_ddi_hierarchical: ddi.Codebook): # And does it raise a ValueError if the variable does not exist? with pytest.raises(ValueError): cps_ddi_hierarchical.get_variable_info("foo") - + def test_ddi_codebook_rectangular(cps_ddi: ddi.Codebook): # sample descriptions/names @@ -274,14 +274,12 @@ def test_ddi_codebook_hierarchical(cps_ddi_hierarchical: ddi.Codebook): "\n" "(4) Use it for GOOD -- never for EVIL." ) - - + + def test_complex_ddi_codebook_hierarchical(atus_ddi_hierarchical: ddi.Codebook): """Test ddi with more than two record types""" # sample descriptions/names - assert atus_ddi_hierarchical.samples_description == [ - "ATUS 2024" - ] + assert atus_ddi_hierarchical.samples_description == ["ATUS 2024"] # doi assert atus_ddi_hierarchical.ipums_doi == "DOI:10.18128/D060.V3.3" @@ -293,7 +291,7 @@ def test_complex_ddi_codebook_hierarchical(atus_ddi_hierarchical: ddi.Codebook): assert atus_ddi_hierarchical.file_description.structure == "hierarchical" # rectypes - assert atus_ddi_hierarchical.file_description.rectypes == ['1', '2', '3', '4'] + assert atus_ddi_hierarchical.file_description.rectypes == ["1", "2", "3", "4"] # rectype idvar assert atus_ddi_hierarchical.file_description.rectype_idvar == "RECTYPE"