Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 11, 2024
1 parent a503041 commit 2e67ac0
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 57 deletions.
2 changes: 1 addition & 1 deletion lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"""Automatic concatenation of multiple cubes over one or more existing dimensions."""

from collections import defaultdict, namedtuple
from iris.exceptions import warn_once_at_level

import dask.array as da
import numpy as np

import iris.coords
import iris.cube
import iris.exceptions
from iris.exceptions import warn_once_at_level
from iris.util import array_equal, guess_coord_axis

#
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/analysis/_regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import copy
import functools
from iris.exceptions import warn_once_at_level

import numpy as np
import numpy.ma as ma
Expand All @@ -19,7 +18,7 @@
snapshot_grid,
)
from iris.analysis._scipy_interpolate import _RegularGridInterpolator
from iris.exceptions import IrisImpossibleUpdateWarning
from iris.exceptions import IrisImpossibleUpdateWarning, warn_once_at_level
from iris.util import _meshgrid, guess_coord_axis


Expand Down
3 changes: 1 addition & 2 deletions lib/iris/analysis/calculus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import re
from iris.exceptions import warn_once_at_level

import cf_units
import numpy as np
Expand All @@ -22,7 +21,7 @@
import iris.analysis.maths
import iris.coord_systems
import iris.coords
from iris.exceptions import IrisUserWarning
from iris.exceptions import IrisUserWarning, warn_once_at_level
from iris.util import delta

__all__ = ["DIRECTIONAL_NAMES", "cube_delta", "curl", "differentiate"]
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/cartography.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from collections import namedtuple
import copy
from iris.exceptions import warn_once_at_level

import cartopy.crs as ccrs
import cartopy.img_transform
Expand All @@ -18,6 +17,7 @@
import iris.coord_systems
import iris.coords
import iris.exceptions
from iris.exceptions import warn_once_at_level
from iris.util import _meshgrid

from ._grid_angles import gridcell_angles, rotate_grid_vectors
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/analysis/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
"""

from iris.exceptions import warn_once_at_level

import numpy as np
from shapely.geometry import Polygon

import iris.exceptions
from iris.exceptions import warn_once_at_level


def _extract_relevant_cube_slice(cube, geometry):
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/analysis/maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import inspect
import math
import operator
from iris.exceptions import warn_once_at_level

import cf_units
import dask.array as da
Expand All @@ -22,6 +21,7 @@
from iris.config import get_logger
import iris.coords
import iris.exceptions
from iris.exceptions import warn_once_at_level
import iris.util

# Configure the logger.
Expand Down
51 changes: 37 additions & 14 deletions lib/iris/aux_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
"""Definitions of derived coordinates."""

from abc import ABCMeta, abstractmethod
from iris.exceptions import warn_once_at_level

import cf_units
import dask.array as da
import numpy as np

from iris.common import CFVariableMixin, CoordMetadata, metadata_manager_factory
import iris.coords
from iris.exceptions import IrisIgnoringBoundsWarning
from iris.exceptions import IrisIgnoringBoundsWarning, warn_once_at_level


class AuxCoordFactory(CFVariableMixin, metaclass=ABCMeta):
Expand Down Expand Up @@ -429,7 +428,9 @@ def _check_dependencies(pressure_at_top, sigma, surface_air_pressure):
f"Coordinate '{coord.name()}' has bounds. These will "
"be disregarded"
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)

# Check units
if sigma.units.is_unknown():
Expand Down Expand Up @@ -704,7 +705,9 @@ def update(self, old_coord, new_coord=None):
"Orography coordinate {!r} has bounds."
" These will be disregarded.".format(new_coord.name())
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)
self.orography = new_coord


Expand Down Expand Up @@ -968,7 +971,9 @@ def _check_dependencies(sigma, eta, depth, depth_c, nsigma, zlev):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(term, coord.name())
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)

for coord, term in ((depth_c, "depth_c"), (nsigma, "nsigma")):
if coord is not None and coord.shape != (1,):
Expand Down Expand Up @@ -1125,7 +1130,9 @@ def make_coord(self, coord_dims_func):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(key, name)
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)
# Swap bounds with points.
bds_shape = list(nd_points_by_key[key].shape) + [1]
bounds = nd_points_by_key[key].reshape(bds_shape)
Expand Down Expand Up @@ -1205,7 +1212,9 @@ def _check_dependencies(sigma, eta, depth):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(term, coord.name())
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)

# Check units.
if sigma is not None and sigma.units.is_unknown():
Expand Down Expand Up @@ -1281,7 +1290,9 @@ def make_coord(self, coord_dims_func):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(key, name)
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)
# Swap bounds with points.
bds_shape = list(nd_points_by_key[key].shape) + [1]
bounds = nd_points_by_key[key].reshape(bds_shape)
Expand Down Expand Up @@ -1372,7 +1383,9 @@ def _check_dependencies(s, c, eta, depth, depth_c):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(term, coord.name())
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)

if depth_c is not None and depth_c.shape != (1,):
msg = "Expected scalar {} coordinate {!r}: got shape {!r}.".format(
Expand Down Expand Up @@ -1466,7 +1479,9 @@ def make_coord(self, coord_dims_func):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(key, name)
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)
# Swap bounds with points.
bds_shape = list(nd_points_by_key[key].shape) + [1]
bounds = nd_points_by_key[key].reshape(bds_shape)
Expand Down Expand Up @@ -1561,7 +1576,9 @@ def _check_dependencies(s, eta, depth, a, b, depth_c):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(term, coord.name())
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)

coords = ((a, "a"), (b, "b"), (depth_c, "depth_c"))
for coord, term in coords:
Expand Down Expand Up @@ -1658,7 +1675,9 @@ def make_coord(self, coord_dims_func):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(key, name)
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)
# Swap bounds with points.
bds_shape = list(nd_points_by_key[key].shape) + [1]
bounds = nd_points_by_key[key].reshape(bds_shape)
Expand Down Expand Up @@ -1753,7 +1772,9 @@ def _check_dependencies(s, c, eta, depth, depth_c):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(term, coord.name())
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)

if depth_c is not None and depth_c.shape != (1,):
msg = "Expected scalar depth_c coordinate {!r}: got shape {!r}.".format(
Expand Down Expand Up @@ -1847,7 +1868,9 @@ def make_coord(self, coord_dims_func):
"The {} coordinate {!r} has bounds. "
"These are being disregarded.".format(key, name)
)
warn_once_at_level(msg, category=IrisIgnoringBoundsWarning, stacklevel=2)
warn_once_at_level(
msg, category=IrisIgnoringBoundsWarning, stacklevel=2
)
# Swap bounds with points.
bds_shape = list(nd_points_by_key[key].shape) + [1]
bounds = nd_points_by_key[key].reshape(bds_shape)
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import contextlib
import logging
import os.path
from iris.exceptions import warn_once_at_level

import iris.exceptions
from iris.exceptions import warn_once_at_level


def get_logger(name, datefmt=None, fmt=None, level=None, propagate=None, handler=True):
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/coord_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
from abc import ABCMeta, abstractmethod
from functools import cached_property
import re
from iris.exceptions import warn_once_at_level

import cartopy.crs as ccrs
import numpy as np

from iris._deprecation import warn_deprecated
import iris.exceptions
from iris.exceptions import warn_once_at_level


def _arg_default(value, default, cast_as=float):
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from functools import lru_cache
from itertools import zip_longest
import operator
from iris.exceptions import warn_once_at_level
import zlib

import dask.array as da
Expand All @@ -30,6 +29,7 @@
metadata_manager_factory,
)
import iris.exceptions
from iris.exceptions import warn_once_at_level
import iris.time
import iris.util

Expand Down
2 changes: 1 addition & 1 deletion lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Optional,
Union,
)
from iris.exceptions import warn_once_at_level
from xml.dom.minidom import Document
import zlib

Expand All @@ -44,6 +43,7 @@
import iris.coord_systems
import iris.coords
import iris.exceptions
from iris.exceptions import warn_once_at_level
import iris.util

__all__ = ["Cube", "CubeAttrsDict", "CubeList"]
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ def warn_once(msg, stacklevel, frame, **kwargs):


def warn_once_at_level(msg, stacklevel=0, **kwargs):
"""
Raise a warning only if a similar one hasn't been raised from the same line
"""Raise a warning only if a similar one hasn't been raised from the same line
for a given stack level.
"""
stacklevel += 1
Expand Down
3 changes: 1 addition & 2 deletions lib/iris/experimental/regrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"""
import copy
import functools
from iris.exceptions import warn_once_at_level

import cartopy.crs as ccrs
import numpy as np
Expand All @@ -37,7 +36,7 @@
import iris.analysis.cartography
import iris.coord_systems
import iris.cube
from iris.exceptions import IrisImpossibleUpdateWarning
from iris.exceptions import IrisImpossibleUpdateWarning, warn_once_at_level
from iris.util import _meshgrid

wmsg = (
Expand Down
12 changes: 9 additions & 3 deletions lib/iris/experimental/ugrid/cf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def identify(cls, variables, ignore=None, target=None, warn=True):
f"{nc_var_name}"
)
if warn:
warn_once_at_level(message, category=IrisCfMissingVarWarning)
warn_once_at_level(
message, category=IrisCfMissingVarWarning
)
else:
# Restrict to non-string type i.e. not a
# CFLabelVariable.
Expand Down Expand Up @@ -217,7 +219,9 @@ def identify(cls, variables, ignore=None, target=None, warn=True):
f"referenced by netCDF variable {nc_var_name}"
)
if warn:
warn_once_at_level(message, category=IrisCfMissingVarWarning)
warn_once_at_level(
message, category=IrisCfMissingVarWarning
)
else:
# Restrict to non-string type i.e. not a
# CFLabelVariable.
Expand All @@ -230,7 +234,9 @@ def identify(cls, variables, ignore=None, target=None, warn=True):
f"variable."
)
if warn:
warn_once_at_level(message, category=IrisCfLabelVarWarning)
warn_once_at_level(
message, category=IrisCfLabelVarWarning
)

return result

Expand Down
1 change: 1 addition & 0 deletions lib/iris/experimental/ugrid/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from itertools import groupby
from pathlib import Path
import threading

from iris.exceptions import warn_once_at_level

from ...config import get_logger
Expand Down
6 changes: 4 additions & 2 deletions lib/iris/fileformats/_ff.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"""Provides UK Met Office Fields File (FF) format specific capabilities."""

import os
from iris.exceptions import warn_once_at_level

import numpy as np

from iris.exceptions import (
IrisDefaultingWarning,
IrisLoadWarning,
NotYetImplementedError,
warn_once_at_level,
)
from iris.fileformats._ff_cross_references import STASH_TRANS

Expand Down Expand Up @@ -799,7 +799,9 @@ def _extract_field(self):
"Input field skipped as PPField creation failed :"
" error = {!r}"
)
warn_once_at_level(msg.format(str(valerr)), category=IrisLoadWarning)
warn_once_at_level(
msg.format(str(valerr)), category=IrisLoadWarning
)

def __iter__(self):
return pp._interpret_fields(self._extract_field())
Expand Down
Loading

0 comments on commit 2e67ac0

Please sign in to comment.