Skip to content

Commit

Permalink
chore: update pre-commit hooks (#599)
Browse files Browse the repository at this point in the history
* chore: update pre-commit hooks

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.6 → v0.9.1](astral-sh/ruff-pre-commit@v0.8.6...v0.9.1)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Jan 13, 2025
1 parent 0ecb453 commit 75cdd4a
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ repos:
types: [file, python]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.8.6"
rev: "v0.9.1"
hooks:
- id: ruff
types: [file, python]
Expand Down
4 changes: 1 addition & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def _write_iris_config(session: nox.sessions.Session) -> None:
[Resources]
test_data_dir = {test_data_dir}
[System]
udunits2_path = {
os.path.join(session.virtualenv.location,'lib', 'libudunits2.so')
}
udunits2_path = {os.path.join(session.virtualenv.location, "lib", "libudunits2.so")}
"""

print("Iris config\n-----------")
Expand Down
6 changes: 3 additions & 3 deletions src/iris_grib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"rjtd": "Tokyo, Japan Meteorological Agency",
"55": "San Francisco",
"kwbc": (
"US National Weather Service, National Centres for " "Environmental Prediction"
"US National Weather Service, National Centres for Environmental Prediction"
),
}

Expand Down Expand Up @@ -612,7 +612,7 @@ def _get_verification_date(self):
# for all the days included in the P2 period. The units of P2
# are given by the contents of octet 18 and Table 4.
raise TranslationError(
"unhandled grib1 timeRangeIndicator " "= 51 (avg of avgs)"
"unhandled grib1 timeRangeIndicator = 51 (avg of avgs)"
)
elif time_range_indicator == 113:
# Average of N forecasts (or initialized analyses); each
Expand Down Expand Up @@ -661,7 +661,7 @@ def _get_verification_date(self):
time_diff = P1
else:
raise TranslationError(
"unhandled grib1 timeRangeIndicator " "= %i" % time_range_indicator
"unhandled grib1 timeRangeIndicator = %i" % time_range_indicator
)

# Get the timeunit interval.
Expand Down
2 changes: 1 addition & 1 deletion src/iris_grib/_grib1_load_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def grib1_convert(grib):
(grib.table2Version == 1) and (grib.indicatorOfParameter >= 128)
):
long_name = (
f"UNKNOWN LOCAL PARAM {grib.indicatorOfParameter}" f".{grib.table2Version}"
f"UNKNOWN LOCAL PARAM {grib.indicatorOfParameter}.{grib.table2Version}"
)
units = "???"

Expand Down
37 changes: 13 additions & 24 deletions src/iris_grib/_load_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _hindcast_fix(forecast_time):
original_forecast_time = forecast_time
forecast_time = -(uft - 2 * HIGHBIT)
if options.warn_on_unsupported:
msg = "Re-interpreting large grib forecastTime " "from {} to {}.".format(
msg = "Re-interpreting large grib forecastTime from {} to {}.".format(
original_forecast_time, forecast_time
)
warnings.warn(msg, HindcastOverflowWarning)
Expand Down Expand Up @@ -521,7 +521,7 @@ def grid_definition_template_0_and_1(section, metadata, y_name, x_name, cs):
section["numberOfOctectsForNumberOfPoints"] != 0
or section["interpretationOfNumberOfPoints"] != 0
):
msg = "Grid definition section 3 contains unsupported " "quasi-regular grid"
msg = "Grid definition section 3 contains unsupported quasi-regular grid"
raise TranslationError(msg)

scan = scanning_mode(section["scanningMode"])
Expand Down Expand Up @@ -1259,7 +1259,7 @@ def grid_definition_template_90(section, metadata):
# diameters rely on the satellite being over the equator.
if sub_satellite_lat != 0:
raise TranslationError(
"Unsupported non-zero latitude for " "space-view perspective."
"Unsupported non-zero latitude for space-view perspective."
)
sub_satellite_lon = (
section["longitudeOfSubSatellitePoint"] * _GRID_ACCURACY_IN_DEGREES
Expand Down Expand Up @@ -2018,13 +2018,9 @@ def generating_process(section, include_forecast_process=True):
if options.warn_on_unsupported:
# Reference Code Table 4.3.
warnings.warn("Unable to translate type of generating process.")
warnings.warn(
"Unable to translate background generating " "process identifier."
)
warnings.warn("Unable to translate background generating process identifier.")
if include_forecast_process:
warnings.warn(
"Unable to translate forecast generating " "process identifier."
)
warnings.warn("Unable to translate forecast generating process identifier.")


def data_cutoff(hoursAfterDataCutoff, minutesAfterDataCutoff):
Expand All @@ -2043,7 +2039,7 @@ def data_cutoff(hoursAfterDataCutoff, minutesAfterDataCutoff):
if hoursAfterDataCutoff != _MDI or minutesAfterDataCutoff != _MDI:
if options.warn_on_unsupported:
warnings.warn(
'Unable to translate "hours and/or minutes ' 'after data cutoff".'
'Unable to translate "hours and/or minutes after data cutoff".'
)


Expand All @@ -2060,8 +2056,7 @@ def statistical_method_name(section):
else:
# This should *never* happen, as only called by pdt 8 and 15.
msg = (
"Internal error: can't get statistical method for unsupported "
"pdt : 4.{:d}."
"Internal error: can't get statistical method for unsupported pdt : 4.{:d}."
)
raise ValueError(msg.format(section_number))
statistic_code = section[stat_keyname]
Expand Down Expand Up @@ -2117,7 +2112,7 @@ def statistical_cell_method(section):
# is all we currently support.
# The exact interpretation of this is still unclear so we also accept
# a missing value.
msg = "grib statistic time-increment type [{}] " "is not supported.".format(
msg = "grib statistic time-increment type [{}] is not supported.".format(
increment_typecode
)
raise TranslationError(msg)
Expand Down Expand Up @@ -2337,17 +2332,11 @@ def product_definition_template_9(section, metadata, frt_coord):
# Type is "above upper level".
threshold_value = section["scaledValueOfUpperLimit"]
if threshold_value == _MDI:
msg = (
"Product definition section 4 has missing "
"scaled value of upper limit"
)
msg = "Product definition section 4 has missing scaled value of upper limit"
raise TranslationError(msg)
threshold_scaling = section["scaleFactorOfUpperLimit"]
if threshold_scaling == _MDI:
msg = (
"Product definition section 4 has missing "
"scale factor of upper limit"
)
msg = "Product definition section 4 has missing scale factor of upper limit"
raise TranslationError(msg)
# Encode threshold information.
threshold = unscale(threshold_value, threshold_scaling)
Expand Down Expand Up @@ -2668,7 +2657,7 @@ def product_definition_section(section, metadata, discipline, tablesVersion, rt_
elif template == 40:
product_definition_template_40(section, metadata, rt_coord)
else:
msg = "Product definition template [{}] is not " "supported".format(template)
msg = "Product definition template [{}] is not supported".format(template)
raise TranslationError(msg)

# Translate GRIB2 phenomenon to CF phenomenon.
Expand Down Expand Up @@ -2722,7 +2711,7 @@ def data_representation_section(section):
supported_templates = grid_point_templates + spectral_templates

if template not in supported_templates:
msg = "Data Representation Section Template [{}] is not " "supported".format(
msg = "Data Representation Section Template [{}] is not supported".format(
template
)
raise TranslationError(msg)
Expand Down Expand Up @@ -2757,7 +2746,7 @@ def bitmap_section(section):
bitMapIndicator = section["bitMapIndicator"]

if bitMapIndicator not in [_BITMAP_CODE_NONE, _BITMAP_CODE_PRESENT]:
msg = "Bitmap Section 6 contains unsupported " "bitmap indicator [{}]".format(
msg = "Bitmap Section 6 contains unsupported bitmap indicator [{}]".format(
bitMapIndicator
)
raise TranslationError(msg)
Expand Down
22 changes: 10 additions & 12 deletions src/iris_grib/_save_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ def dx_dy(x_coord, y_coord, grib):
eccodes.codes_set(grib, "iDirectionIncrement", round(1e6 * float(abs(x_step))))
else:
raise ValueError(
"X coordinate must be in degrees, not {}" ".".format(x_coord.units)
"X coordinate must be in degrees, not {}.".format(x_coord.units)
)
if y_coord.units == "degrees":
eccodes.codes_set(grib, "jDirectionIncrement", round(1e6 * float(abs(y_step))))
else:
raise ValueError(
"Y coordinate must be in degrees, not {}" ".".format(y_coord.units)
"Y coordinate must be in degrees, not {}.".format(y_coord.units)
)


Expand Down Expand Up @@ -525,7 +525,7 @@ def grid_definition_template_12(cube, grib):
x_step = step(x_cm, atol=1)
y_step = step(y_cm, atol=1)
except ValueError:
msg = "Irregular coordinates not supported for Transverse " "Mercator."
msg = "Irregular coordinates not supported for Transverse Mercator."
raise TranslationError(msg)
eccodes.codes_set(grib, "Di", abs(x_step))
eccodes.codes_set(grib, "Dj", abs(y_step))
Expand Down Expand Up @@ -747,7 +747,7 @@ def grid_definition_template_140(cube, grib):
x_step = step(x_mm, atol=1)
y_step = step(y_mm, atol=1)
except ValueError:
msg = "Irregular coordinates not supported for Lambert " "Azimuthal Equal Area."
msg = "Irregular coordinates not supported for Lambert Azimuthal Equal Area."
raise TranslationError(msg)
eccodes.codes_set(grib, "Dx", abs(x_step))
eccodes.codes_set(grib, "Dy", abs(y_step))
Expand Down Expand Up @@ -934,12 +934,12 @@ def _non_missing_forecast_period(cube):
else:
if not fp_coord.has_bounds():
raise TranslationError(
"bounds on 'time' coordinate requires bounds on" " 'forecast_period'."
"bounds on 'time' coordinate requires bounds on 'forecast_period'."
)
fp = fp_coord.bounds[0][0]

if fp - int(fp):
warnings.warn("forecast_period encoding problem: " "scaling required.")
warnings.warn("forecast_period encoding problem: scaling required.")
fp = int(fp)

return rt, rt_meaning, fp, grib_time_code
Expand Down Expand Up @@ -973,7 +973,7 @@ def _missing_forecast_period(cube):
fp = t - frt
integer_fp = int(fp)
if integer_fp != fp:
msg = "Truncating floating point forecast period {} to " "integer value {}"
msg = "Truncating floating point forecast period {} to integer value {}"
warnings.warn(msg.format(fp, integer_fp))
fp = integer_fp
fp_meaning = 1 # Hours
Expand Down Expand Up @@ -1168,7 +1168,7 @@ def set_fixed_surfaces(cube, grib, full3d_cube=None):
n_levels = np.max(model_levels)
max_valid_nlevels = 9999
if n_levels > max_valid_nlevels:
msg = "model_level_number values are > {} : " "maximum value = {}."
msg = "model_level_number values are > {} : maximum value = {}."
raise ValueError(msg.format(max_valid_nlevels, n_levels))
# In sample data we have seen, there seems to be an extra missing data
# value *before* each set of n-levels coefficients.
Expand Down Expand Up @@ -1226,7 +1226,7 @@ def set_time_range(time_coord, grib):
time_range_in_hours = end_hours - start_hours
integer_hours = int(time_range_in_hours)
if integer_hours != time_range_in_hours:
msg = "Truncating floating point lengthOfTimeRange {} to " "integer value {}"
msg = "Truncating floating point lengthOfTimeRange {} to integer value {}"
warnings.warn(msg.format(time_range_in_hours, integer_hours))
eccodes.codes_set(grib, "lengthOfTimeRange", integer_hours)

Expand Down Expand Up @@ -1580,9 +1580,7 @@ def _product_definition_template_8_10_and_11(cube, grib, full3d_cube=None):
if "time" in cell_method.coord_names
]
if not time_cell_methods:
raise ValueError(
"Expected a cell method with a coordinate name " "of 'time'"
)
raise ValueError("Expected a cell method with a coordinate name of 'time'")
if len(time_cell_methods) > 1:
raise ValueError("Cannot handle multiple 'time' cell methods")
(cell_method,) = time_cell_methods
Expand Down
16 changes: 9 additions & 7 deletions src/iris_grib/grib_phenom_translation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def __getitem__(self, key):
def __setitem__(self, key, value):
if key in self and self[key] is not value:
raise KeyError(
"Attempted to set dict[{}] = {}, "
"but this is already set to {}.".format(key, value, self[key])
"Attempted to set dict[{}] = {}, but this is already set to {}.".format(
key, value, self[key]
)
)
self._super.__setitem__(key, value)

Expand Down Expand Up @@ -106,7 +107,7 @@ def _make_grib1_cf_entry(
if standard_name is not None:
if standard_name not in iris.std_names.STD_NAMES:
warnings.warn(
"{} is not a recognised CF standard name " "(skipping).".format(
"{} is not a recognised CF standard name (skipping).".format(
standard_name
)
)
Expand Down Expand Up @@ -156,8 +157,9 @@ def _make_grib1_cf_entry(
)
if len(extra_dimcoord.points) != 1:
raise ValueError(
"Implied dimension has {} points, "
"currently can only handle 1.".format(len(extra_dimcoord.points))
"Implied dimension has {} points, currently can only handle 1.".format(
len(extra_dimcoord.points)
)
)
association_entry = _make_grib1_cf_entry(
table2_version=int(grib1data.t2version),
Expand Down Expand Up @@ -211,7 +213,7 @@ def _make_grib2_cf_entry(
if standard_name is not None:
if standard_name not in iris.std_names.STD_NAMES:
warnings.warn(
"{} is not a recognised CF standard name " "(skipping).".format(
"{} is not a recognised CF standard name (skipping).".format(
standard_name
)
)
Expand Down Expand Up @@ -273,7 +275,7 @@ def _make_cf_grib2_entry(
long_name = None
if standard_name not in iris.std_names.STD_NAMES:
warnings.warn(
"{} is not a recognised CF standard name " "(skipping).".format(
"{} is not a recognised CF standard name (skipping).".format(
standard_name
)
)
Expand Down
6 changes: 2 additions & 4 deletions src/iris_grib/grib_phenom_translation/_gribcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def _invalid_edition(edition):
msg = f"Invalid grib edition, {edition!r}, for GRIBcode : " "can only be 1 or 2."
msg = f"Invalid grib edition, {edition!r}, for GRIBcode : can only be 1 or 2."
raise ValueError(msg)


Expand Down Expand Up @@ -135,9 +135,7 @@ def __init__(self, **kwargs):
setattr(self, key, value)

def _broken_repr(self):
result = (
f"<{self.__class__.__name__} with invalid content: " f"{self.__dict__}>"
)
result = f"<{self.__class__.__name__} with invalid content: {self.__dict__}>"
return result

def __str__(self):
Expand Down
10 changes: 4 additions & 6 deletions src/iris_grib/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def data(self):
template = grid_section["gridDefinitionTemplateNumber"]
if reduced and template not in (40,):
raise TranslationError(
"Grid definition Section 3 contains " "unsupported quasi-regular grid."
"Grid definition Section 3 contains unsupported quasi-regular grid."
)

if template in _SUPPORTED_GRID_DEFINITIONS:
Expand Down Expand Up @@ -265,10 +265,8 @@ def _bitmap(self, bitmap_section):
elif bitMapIndicator == 255:
bitmap = None
else:
msg = (
"Bitmap Section 6 contains unsupported " "bitmap indicator [{}]".format(
bitMapIndicator
)
msg = "Bitmap Section 6 contains unsupported bitmap indicator [{}]".format(
bitMapIndicator
)
raise TranslationError(msg)
return bitmap
Expand Down Expand Up @@ -490,7 +488,7 @@ def __setitem__(self, key, value):
self._cache[key] = value
else:
raise KeyError(
"{!r} cannot be redefined in " "section {}".format(key, self._number)
"{!r} cannot be redefined in section {}".format(key, self._number)
)

def _get_key_value(self, key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_save_load(self):
self.assertEqual(
co_load.shape,
co_orig.shape,
'Shape of re-loaded "{}" coord is {} ' "instead of {}".format(
'Shape of re-loaded "{}" coord is {} instead of {}'.format(
coord_name, co_load.shape, co_orig.shape
),
)
Expand Down
4 changes: 1 addition & 3 deletions src/iris_grib/tests/test_license_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def test_license_headers(self):
last_change_by_fname = self.last_change_by_fname()
except ValueError:
# Caught the case where this is not a git repo.
return self.skipTest(
"Iris-grib installation did not look like a " "git repo."
)
return self.skipTest("Iris-grib installation did not look like a git repo.")

failed = False
for fname, last_change in sorted(last_change_by_fname.items()):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def test_warn_unknown_pdts(self):
with self.assertRaises(iris.exceptions.TranslationError) as t_err:
_ = next(cube_generator)
self.assertEqual(
"Product definition template [5]" " is not supported",
"Product definition template [5] is not supported",
str(t_err.exception),
)

Expand Down
Loading

0 comments on commit 75cdd4a

Please sign in to comment.