Skip to content

Commit

Permalink
Fix mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder committed Oct 16, 2024
1 parent 76398b9 commit 4d9460c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
34 changes: 11 additions & 23 deletions e3sm_to_cmip/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def _run_info_mode(self): # noqa: C901
for handler in self.handlers:
table_info = _get_table_info(self.tables_path, handler["table"])
if handler["name"] not in table_info["variable_entry"]:
msg = f"Variable {handler['name']} is not included in the table {handler['table']}" # type: ignore
msg = f"Variable {handler['name']} is not included in the table {handler['table']}"
print_message(msg, status="error")
continue
else:
Expand All @@ -687,37 +687,25 @@ def _run_info_mode(self): # noqa: C901
if handler["name"] not in table_info["variable_entry"]:
continue

msg = None
raw_vars = []

if msg is None:
msg = {
"CMIP6 Name": handler["name"],
"CMIP6 Table": handler["table"],
"CMIP6 Units": handler["units"],
"E3SM Variables": ", ".join(handler["raw_variables"]),
}
raw_vars.extend(handler["raw_variables"])
if handler.get("unit_conversion"):
msg["Unit conversion"] = handler["unit_conversion"]
if handler.get("levels"):
msg["Levels"] = handler["levels"]

raw_vars = handler["raw_variables"]
has_vars = True

for raw_var in raw_vars:
if raw_var not in ds.data_vars:
has_vars = False
msg = f"Variable {handler['name']} is not present in the input dataset" # type: ignore

msg = f"Variable {handler['name']} is not present in the input dataset"
print_message(msg, status="error")

break

if not has_vars:
continue

# We test here against the input "freq", because
# atmos mon data satisfies BOTH CMIP6_day.json AND CMIP6_mon.json,
# but we only want the latter in the "hand_msg" output.
# The vars "hass" and "rlut" have multiple freqs.

# We test here against the input "freq", because atmos mon
# data satisfies BOTH CMIP6_day.json AND CMIP6_mon.json, but
# we only want the latter in the "hand_msg" output. The vars
# "hass" and "rlut" have multiple freqs.
if self.freq == "mon" and handler["table"] == "CMIP6_day.json":
continue
if (self.freq == "day" or self.freq == "3hr") and handler[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_raises_error_if_table_does_not_exist_for_freq(self):
base_table="CMIP6_Lmon.json",
freq="3hr",
realm="atm",
tables_path=None,
tables_path=None, # type: ignore
)

def test_raises_error_if_table_could_not_be_found_in_table_path(self):
Expand Down

0 comments on commit 4d9460c

Please sign in to comment.