Skip to content

Commit

Permalink
remaining ACS tasks seem to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreFCruz committed Jun 21, 2024
1 parent 9b79f82 commit ba22888
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
31 changes: 27 additions & 4 deletions folktexts/acs/acs_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@
acs_place_of_birth = ColumnToText(
"POBP",
short_description="place of birth",
value_map=partial(parse_pums_code, file=ACS_POBP_FILE),
value_map=partial(
parse_pums_code,
file=ACS_POBP_FILE,
postprocess=lambda x: x[: x.find("/")].strip(),
),
)

# RELP: Relationship to Reference Person
Expand Down Expand Up @@ -430,8 +434,8 @@
short_description="person has given birth within the last year",
use_value_map_only=True,
value_map={
1: "Person has given birth within the last year: Yes.",
2: "Person has given birth within the last year: No.",
1: "Person has given birth within the last year.",
2: "Person has not given birth within the last year.",
},
missing_value_fill="N/A (less than 15 years old, or greater than 50 years old, or male)",
)
Expand Down Expand Up @@ -485,7 +489,7 @@
acs_poverty_ratio = ColumnToText(
"POVPIP",
short_description="income-to-poverty ratio",
value_map=lambda x: f"{x:.2f}",
value_map=lambda x: f"{x / 100:.1%}",
)

# HINS2: Health Insurance Coverage through Private Company
Expand Down Expand Up @@ -514,6 +518,25 @@
missing_value_fill="N/A (less than 30 years old, or living in institutional group quarters)",
)

# PUMA: Public Use Microdata Area Code
# TODO: assign meaningful natural-text values to PUMA codes
acs_puma_col = ColumnToText(
"PUMA",
short_description="Public Use Microdata Area (PUMA) code",
use_value_map_only=True,
value_map=lambda x: f"PUMA code: {int(x)}",
# missing_value_fill="N/A (less than 16 years old)",
)

# POWPUMA: Place of Work PUMA
acs_powpuma_col = ColumnToText(
"POWPUMA",
short_description="place of work PUMA",
use_value_map_only=True,
value_map=lambda x: f"Place of work PUMA code: {int(x)}",
# missing_value_fill="N/A (not a worker, or worker who worked at home)",
)

# HINS2: Health Insurance Coverage through Private Company (Thresholded)
acs_health_ins_2_qa = MultipleChoiceQA(
column=acs_health_insurance_threshold.apply_to_column_name("HINS2"),
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion folktexts/col_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ def _helper_func(value: object) -> str:

def __getitem__(self, value: object) -> str:
"""Returns the textual representation of the given data value."""
return self.value_map(value)
# NOTE: `value != value` is a check for NaN values
return self._missing_value_fill if value != value else self.value_map(value)

def get_text(self, value: object) -> str:
"""Returns the natural text representation of the given data value."""
Expand Down

0 comments on commit ba22888

Please sign in to comment.