Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/ogrre_data_cleaning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
string_to_date,
string_to_float,
string_to_int,
texas_rrc_clean_lease_field_or_operator,
)

__version__ = "0.1.0"
Expand All @@ -25,4 +26,5 @@
"string_to_date",
"string_to_float",
"string_to_int",
"texas_rrc_clean_lease_field_or_operator",
]
27 changes: 27 additions & 0 deletions src/ogrre_data_cleaning/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,31 @@ def convert_hole_size_to_decimal(size_str, options={}):
print(f"DEBUG: Error parsing size: {e}")
return None

def texas_rrc_clean_lease_field_or_operator(s, options={}):
"""
Forward-fills values for 'lease_field' or 'lease_operator'.
If input 's' is not null, returns 's'.
If 's' is null, returns whatever previous value is saved in 'lease_field' or
'lease_operator' key in options context. Returns None if no value is saved.
"""
if s is not None and s != "":
return s

if not isinstance(options, dict):
return None

attribute_key = options.get("attribute_key") or options.get("key")
if attribute_key in ["lease_field", "lease_operator"]:
return options.get(attribute_key)

if options.get("lease_field") is not None:
return options.get("lease_field")
if options.get("lease_operator") is not None:
return options.get("lease_operator")

return None


CLEANING_FUNCTIONS = {
"clean_bool": clean_bool,
"string_to_int": string_to_int,
Expand All @@ -842,9 +867,11 @@ def convert_hole_size_to_decimal(size_str, options={}):
"clean_depth": clean_depth,
"newts_clean_units": newts_clean_units,
"newts_clean_epa_methods": newts_clean_epa_methods,
"texas_rrc_clean_lease_field_or_operator": texas_rrc_clean_lease_field_or_operator,
}



if __name__ == '__main__':

# LLM hole size cleaning
Expand Down
Binary file modified src/ogrre_data_cleaning/processor_schemas/RRC Schema.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"occurrence": "Optional once",
"grouping": null,
"database_data_type": "str",
"cleaning_function": null,
"cleaning_function": "texas_rrc_clean_lease_field_or_operator",
"accepted_range": null,
"field_specific_notes": null,
"model_enabled": null
Expand Down Expand Up @@ -120,7 +120,7 @@
"occurrence": "Optional once",
"grouping": null,
"database_data_type": "str",
"cleaning_function": null,
"cleaning_function": "texas_rrc_clean_lease_field_or_operator",
"accepted_range": null,
"field_specific_notes": null,
"model_enabled": null
Expand Down
33 changes: 33 additions & 0 deletions tests/test_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
newts_clean_units,
string_to_float,
string_to_int,
texas_rrc_clean_lease_field_or_operator,
)


Expand All @@ -29,6 +30,7 @@ def test_package_exports_cleaning_functions():
"clean_depth",
"newts_clean_units",
"newts_clean_epa_methods",
"texas_rrc_clean_lease_field_or_operator",
]

assert list(CLEANING_FUNCTIONS) == expected_names
Expand Down Expand Up @@ -378,3 +380,34 @@ def test_cleaning_functions_accept_options():
assert clean_depth("100", options=custom_options) == 100.0
assert newts_clean_units("Feet", options=custom_options) == "Feet"
assert newts_clean_epa_methods("EPA 8260B", options=custom_options) == "EPA 8260B"
assert (
texas_rrc_clean_lease_field_or_operator("Test Lease", options=custom_options)
== "Test Lease"
)


@pytest.mark.unit
def test_texas_rrc_clean_lease_field_or_operator():
# Non-null input returns non-null input
assert texas_rrc_clean_lease_field_or_operator("LEASE A") == "LEASE A"

# Null input with no saved options returns None
assert texas_rrc_clean_lease_field_or_operator(None, options={}) is None
assert texas_rrc_clean_lease_field_or_operator("", options={}) is None

# Null input with saved lease_field in options returns saved lease_field
opts_field = {"lease_field": "SAVED LEASE FIELD", "attribute_key": "lease_field"}
assert texas_rrc_clean_lease_field_or_operator(None, options=opts_field) == "SAVED LEASE FIELD"
assert texas_rrc_clean_lease_field_or_operator("", options=opts_field) == "SAVED LEASE FIELD"

# Null input with saved lease_operator in options returns saved lease_operator
opts_operator = {"lease_operator": "SAVED OPERATOR", "attribute_key": "lease_operator"}
assert (
texas_rrc_clean_lease_field_or_operator(None, options=opts_operator)
== "SAVED OPERATOR"
)
assert (
texas_rrc_clean_lease_field_or_operator("", options=opts_operator)
== "SAVED OPERATOR"
)

Loading