diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0233955d77..7c95eeaca3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -29,7 +29,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1.0 hooks: - id: black pass_filenames: false diff --git a/docs/gallery_code/general/plot_lineplot_with_legend.py b/docs/gallery_code/general/plot_lineplot_with_legend.py index 78401817ba..aad7906acd 100644 --- a/docs/gallery_code/general/plot_lineplot_with_legend.py +++ b/docs/gallery_code/general/plot_lineplot_with_legend.py @@ -24,7 +24,6 @@ def main(): ) for cube in temperature.slices("longitude"): - # Create a string label to identify this cube (i.e. latitude: value). cube_label = "latitude: %s" % cube.coord("latitude").points[0] diff --git a/docs/gallery_code/general/plot_projections_and_annotations.py b/docs/gallery_code/general/plot_projections_and_annotations.py index 75122591b9..2cf42e66e0 100644 --- a/docs/gallery_code/general/plot_projections_and_annotations.py +++ b/docs/gallery_code/general/plot_projections_and_annotations.py @@ -26,7 +26,6 @@ def make_plot(projection_name, projection_crs): - # Create a matplotlib Figure. plt.figure() diff --git a/docs/gallery_code/general/plot_zonal_means.py b/docs/gallery_code/general/plot_zonal_means.py index 08a9578e63..195f8b4bb0 100644 --- a/docs/gallery_code/general/plot_zonal_means.py +++ b/docs/gallery_code/general/plot_zonal_means.py @@ -16,7 +16,6 @@ def main(): - # Loads air_temp.pp and "collapses" longitude into a single, average value. fname = iris.sample_data_path("air_temp.pp") temperature = iris.load_cube(fname) diff --git a/docs/gallery_code/meteorology/plot_lagged_ensemble.py b/docs/gallery_code/meteorology/plot_lagged_ensemble.py index 5cd2752f39..e15aa0e6ef 100644 --- a/docs/gallery_code/meteorology/plot_lagged_ensemble.py +++ b/docs/gallery_code/meteorology/plot_lagged_ensemble.py @@ -86,7 +86,6 @@ def main(): # Iterate over all possible latitude longitude slices. for cube in last_timestep.slices(["latitude", "longitude"]): - # Get the ensemble member number from the ensemble coordinate. ens_member = cube.coord("realization").points[0] diff --git a/docs/src/userguide/plotting_examples/1d_with_legend.py b/docs/src/userguide/plotting_examples/1d_with_legend.py index 9b9fd8a49d..626335af45 100644 --- a/docs/src/userguide/plotting_examples/1d_with_legend.py +++ b/docs/src/userguide/plotting_examples/1d_with_legend.py @@ -13,7 +13,6 @@ temperature = temperature[5:9, :] for cube in temperature.slices("longitude"): - # Create a string label to identify this cube (i.e. latitude: value) cube_label = "latitude: %s" % cube.coord("latitude").points[0] diff --git a/lib/iris/__init__.py b/lib/iris/__init__.py index 896b850541..a81d25add3 100644 --- a/lib/iris/__init__.py +++ b/lib/iris/__init__.py @@ -175,7 +175,6 @@ def __init__(self, datum_support=False, pandas_ndim=False): self.__dict__["pandas_ndim"] = pandas_ndim def __repr__(self): - # msg = ('Future(example_future_flag={})') # return msg.format(self.example_future_flag) msg = "Future(datum_support={}, pandas_ndim={})" diff --git a/lib/iris/_merge.py b/lib/iris/_merge.py index bc12080523..5ca5f31a8e 100644 --- a/lib/iris/_merge.py +++ b/lib/iris/_merge.py @@ -1418,6 +1418,7 @@ def _define_space(self, space, positions, indexes, function_matrix): participates in a functional relationship. """ + # Heuristic reordering of coordinate defintion indexes into # preferred dimension order. def axis_and_name(name): diff --git a/lib/iris/analysis/__init__.py b/lib/iris/analysis/__init__.py index 55d5d5d93e..f34cda1402 100644 --- a/lib/iris/analysis/__init__.py +++ b/lib/iris/analysis/__init__.py @@ -296,7 +296,6 @@ def _dimensional_metadata_comparison(*cubes, object_get=None): # for coordinate groups for cube, coords in zip(cubes, all_coords): for coord in coords: - # if this coordinate has already been processed, then continue on # to the next one if id(coord) in processed_coords: diff --git a/lib/iris/analysis/_area_weighted.py b/lib/iris/analysis/_area_weighted.py index edbfd41ef9..3b728e9a43 100644 --- a/lib/iris/analysis/_area_weighted.py +++ b/lib/iris/analysis/_area_weighted.py @@ -853,7 +853,7 @@ def _calculate_regrid_area_weighted_weights( cached_x_bounds = [] cached_x_indices = [] max_x_indices = 0 - for (x_0, x_1) in grid_x_bounds: + for x_0, x_1 in grid_x_bounds: if grid_x_decreasing: x_0, x_1 = x_1, x_0 x_bounds, x_indices = _cropped_bounds(src_x_bounds, x_0, x_1) diff --git a/lib/iris/analysis/_interpolation.py b/lib/iris/analysis/_interpolation.py index 2a7dfa6e62..f5e89a9e51 100644 --- a/lib/iris/analysis/_interpolation.py +++ b/lib/iris/analysis/_interpolation.py @@ -268,7 +268,7 @@ def _account_for_circular(self, points, data): """ from iris.analysis.cartography import wrap_lons - for (circular, modulus, index, dim, offset) in self._circulars: + for circular, modulus, index, dim, offset in self._circulars: if modulus: # Map all the requested values into the range of the source # data (centred over the centre of the source data to allow diff --git a/lib/iris/analysis/_scipy_interpolate.py b/lib/iris/analysis/_scipy_interpolate.py index fc64249729..bfa070c7c7 100644 --- a/lib/iris/analysis/_scipy_interpolate.py +++ b/lib/iris/analysis/_scipy_interpolate.py @@ -225,7 +225,6 @@ def compute_interp_weights(self, xi, method=None): prepared = (xi_shape, method) + self._find_indices(xi.T) if method == "linear": - xi_shape, method, indices, norm_distances, out_of_bounds = prepared # Allocate arrays for describing the sparse matrix. diff --git a/lib/iris/analysis/calculus.py b/lib/iris/analysis/calculus.py index c530dbd216..75b7d86406 100644 --- a/lib/iris/analysis/calculus.py +++ b/lib/iris/analysis/calculus.py @@ -594,7 +594,6 @@ def curl(i_cube, j_cube, k_cube=None): horiz_cs, (iris.coord_systems.GeogCS, iris.coord_systems.RotatedGeogCS) ) if not spherical_coords: - # TODO Implement some mechanism for conforming to a common grid dj_dx = _curl_differentiate(j_cube, x_coord) prototype_diff = dj_dx diff --git a/lib/iris/analysis/trajectory.py b/lib/iris/analysis/trajectory.py index c21d71d48c..24f7a9dede 100644 --- a/lib/iris/analysis/trajectory.py +++ b/lib/iris/analysis/trajectory.py @@ -85,7 +85,6 @@ def __init__(self, waypoints, sample_count=10): cur_seg = segments[cur_seg_i] len_accum = cur_seg.length for p in range(self.sample_count): - # calculate the sample position along our total length sample_at_len = p * sample_step diff --git a/lib/iris/common/metadata.py b/lib/iris/common/metadata.py index 8ec39bb4b1..cb3149fe58 100644 --- a/lib/iris/common/metadata.py +++ b/lib/iris/common/metadata.py @@ -969,6 +969,7 @@ def _combine_lenient(self, other): A list of combined metadata member values. """ + # Perform "strict" combination for "coord_system" and "climatological". def func(field): left = getattr(self, field) @@ -1024,6 +1025,7 @@ def _difference_lenient(self, other): A list of difference metadata member values. """ + # Perform "strict" difference for "coord_system" and "climatological". def func(field): left = getattr(self, field) diff --git a/lib/iris/coord_categorisation.py b/lib/iris/coord_categorisation.py index 72019b4b87..698b4828f1 100644 --- a/lib/iris/coord_categorisation.py +++ b/lib/iris/coord_categorisation.py @@ -90,6 +90,7 @@ def vectorised_fn(*args): # coordinates only # + # Private "helper" function def _pt_date(coord, time): """ diff --git a/lib/iris/coord_systems.py b/lib/iris/coord_systems.py index 802571925e..edf0c1871b 100644 --- a/lib/iris/coord_systems.py +++ b/lib/iris/coord_systems.py @@ -478,7 +478,6 @@ def datum(self, value): @classmethod def from_datum(cls, datum, longitude_of_prime_meridian=None): - crs = super().__new__(cls) crs._semi_major_axis = None @@ -949,7 +948,6 @@ def __init__( false_northing=None, ellipsoid=None, ): - """ Constructs a Geostationary coord system. diff --git a/lib/iris/coords.py b/lib/iris/coords.py index cfcdcd92a0..91bb786ae8 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -2846,7 +2846,6 @@ def _new_bounds_requirements(self, bounds): n_bounds = bounds.shape[-1] n_points = bounds.shape[0] if n_points > 1: - directions = set() for b_index in range(n_bounds): monotonic, direction = iris.util.monotonic( diff --git a/lib/iris/cube.py b/lib/iris/cube.py index c60896f718..abe37c35fb 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -2688,7 +2688,6 @@ def subset(self, coord): coord_to_extract in self.aux_coords and len(coord_to_extract.points) == 1 ): - # Default to returning None result = None diff --git a/lib/iris/experimental/ugrid/mesh.py b/lib/iris/experimental/ugrid/mesh.py index d18e1b2026..0d566da73f 100644 --- a/lib/iris/experimental/ugrid/mesh.py +++ b/lib/iris/experimental/ugrid/mesh.py @@ -3127,9 +3127,7 @@ def _construct_access_arrays(self): flat_inds_safe = al.where(missing_inds, 0, flat_inds_nomask) # Here's the core indexing operation. # The comma applies all inds-array values to the *first* dimension. - bounds = node_points[ - flat_inds_safe, - ] + bounds = node_points[flat_inds_safe,] # Fix 'missing' locations, and restore the proper shape. bounds = al.ma.masked_array(bounds, missing_inds) bounds = bounds.reshape(indices.shape) diff --git a/lib/iris/experimental/ugrid/metadata.py b/lib/iris/experimental/ugrid/metadata.py index ae0b787908..44bbe04fe9 100644 --- a/lib/iris/experimental/ugrid/metadata.py +++ b/lib/iris/experimental/ugrid/metadata.py @@ -53,6 +53,7 @@ def _combine_lenient(self, other): A list of combined metadata member values. """ + # Perform "strict" combination for "cf_role", "start_index", "location_axis". def func(field): left = getattr(self, field) @@ -113,6 +114,7 @@ def _difference_lenient(self, other): A list of difference metadata member values. """ + # Perform "strict" difference for "cf_role", "start_index", "location_axis". def func(field): left = getattr(self, field) @@ -233,6 +235,7 @@ def _difference_lenient(self, other): A list of difference metadata member values. """ + # Perform "strict" difference for "topology_dimension", # "node_dimension", "edge_dimension" and "face_dimension". def func(field): @@ -297,6 +300,7 @@ def _combine_lenient(self, other): A list of combined metadata member values. """ + # It is actually "strict" : return None except where members are equal. def func(field): left = getattr(self, field) @@ -352,6 +356,7 @@ def _difference_lenient(self, other): A list of different metadata member values. """ + # Perform "strict" difference for location / axis. def func(field): left = getattr(self, field) diff --git a/lib/iris/fileformats/abf.py b/lib/iris/fileformats/abf.py index 5c70c5acf2..4dcd5ce6aa 100644 --- a/lib/iris/fileformats/abf.py +++ b/lib/iris/fileformats/abf.py @@ -219,7 +219,6 @@ def load_cubes(filespecs, callback=None): for filespec in filespecs: for filename in glob.glob(filespec): - field = ABFField(filename) cube = field.to_cube() diff --git a/lib/iris/fileformats/name_loaders.py b/lib/iris/fileformats/name_loaders.py index d15a3717d0..b9b64a343e 100644 --- a/lib/iris/fileformats/name_loaders.py +++ b/lib/iris/fileformats/name_loaders.py @@ -994,7 +994,6 @@ def load_NAMEIII_version2(filename): # using the next() method. This will come in handy as we wish to # progress through the file line by line. with open(filename, "r") as file_handle: - # define a dictionary to hold the header metadata about this file header = read_header(file_handle) @@ -1005,7 +1004,6 @@ def load_NAMEIII_version2(filename): column_headings = {} datacol1 = header["Number of preliminary cols"] for line in file_handle: - data = [col.strip() for col in line.split(",")][:-1] # If first column is not zero we have reached the end diff --git a/lib/iris/fileformats/pp.py b/lib/iris/fileformats/pp.py index bc35acb3b3..cff088cf89 100644 --- a/lib/iris/fileformats/pp.py +++ b/lib/iris/fileformats/pp.py @@ -625,7 +625,7 @@ def __getstate__(self): def __setstate__(self, state): # Because we have __slots__, this is needed to support Pickle.load() # (Use setattr, as there is no object dictionary.) - for (key, value) in state: + for key, value in state: setattr(self, key, value) def __eq__(self, other): @@ -2029,10 +2029,8 @@ def pp_filter(field): res = True if field.stash not in _STASH_ALLOW: if pp_constraints.get("stash"): - res = False for call_func in pp_constraints["stash"]: - if call_func(str(field.stash)): res = True break diff --git a/lib/iris/fileformats/pp_load_rules.py b/lib/iris/fileformats/pp_load_rules.py index ebccec47ee..11d03e978a 100644 --- a/lib/iris/fileformats/pp_load_rules.py +++ b/lib/iris/fileformats/pp_load_rules.py @@ -756,7 +756,6 @@ def date2year(t_in): ) ) ): - coords_and_dims.append( _new_coord_and_dims( do_vector, diff --git a/lib/iris/fileformats/rules.py b/lib/iris/fileformats/rules.py index 07ed5eb8ce..51940b7c4d 100644 --- a/lib/iris/fileformats/rules.py +++ b/lib/iris/fileformats/rules.py @@ -394,7 +394,7 @@ def _load_pairs_from_fields_and_filenames( yield (cube, field) regrid_cache = {} - for (cube, factories, field) in results_needing_reference: + for cube, factories, field in results_needing_reference: _resolve_factory_references( cube, factories, concrete_reference_targets, regrid_cache ) diff --git a/lib/iris/fileformats/um/_fast_load_structured_fields.py b/lib/iris/fileformats/um/_fast_load_structured_fields.py index d193aa30ce..64b7f8e891 100644 --- a/lib/iris/fileformats/um/_fast_load_structured_fields.py +++ b/lib/iris/fileformats/um/_fast_load_structured_fields.py @@ -133,6 +133,7 @@ def element_arrays_and_dims(self): def _field_vector_element_arrays(self): """Define the field components used in the structure analysis.""" + # Define functions to make t1 and t2 values as date-time tuples. # These depend on header version (PPField2 has no seconds values). def t1_fn(fld): diff --git a/lib/iris/quickplot.py b/lib/iris/quickplot.py index 18ed2554a3..6006314265 100644 --- a/lib/iris/quickplot.py +++ b/lib/iris/quickplot.py @@ -45,7 +45,6 @@ def _title(cube_or_coord, with_units): or units.is_no_unit() or units == cf_units.Unit("1") ): - if _use_symbol(units): units = units.symbol elif units.is_time_reference(): diff --git a/lib/iris/tests/graphics/__init__.py b/lib/iris/tests/graphics/__init__.py index a083de3934..544d989564 100755 --- a/lib/iris/tests/graphics/__init__.py +++ b/lib/iris/tests/graphics/__init__.py @@ -187,7 +187,6 @@ def check_graphic(test_id: str, results_dir: Union[str, Path]) -> None: try: def _create_missing(phash: str) -> None: - output_path = test_output_dir / (test_id + ".png") print(f"Creating image file: {output_path}") @@ -214,7 +213,6 @@ def _create_missing(phash: str) -> None: phash = get_phash(buffer) if test_id in repo: - expected = hex_to_hash(repo[test_id]) # Calculate hamming distance vector for the result hash. diff --git a/lib/iris/tests/integration/test_Datums.py b/lib/iris/tests/integration/test_Datums.py index 77b7f28249..6953534f2d 100755 --- a/lib/iris/tests/integration/test_Datums.py +++ b/lib/iris/tests/integration/test_Datums.py @@ -23,7 +23,6 @@ def setUp(self): self.start_crs = ccrs.OSGB(False) def test_transform_points_datum(self): - # Iris version wgs84 = GeogCS.from_datum("WGS84") iris_cs = LambertConformal( diff --git a/lib/iris/tests/test_cdm.py b/lib/iris/tests/test_cdm.py index 0615dc39bf..8f2a9b474d 100644 --- a/lib/iris/tests/test_cdm.py +++ b/lib/iris/tests/test_cdm.py @@ -349,7 +349,6 @@ def test_similar_coord(self): ) def test_cube_summary_cell_methods(self): - cube = self.cube_2d.copy() # Create a list of values used to create cell methods diff --git a/lib/iris/tests/test_cf.py b/lib/iris/tests/test_cf.py index 034fb1dbda..bf3cddb8b7 100644 --- a/lib/iris/tests/test_cf.py +++ b/lib/iris/tests/test_cf.py @@ -276,9 +276,7 @@ def test_destructor(self): didn't exist because opening the dataset had failed. """ with self.temp_filename(suffix=".nc") as fn: - with open(fn, "wb+") as fh: - fh.write( b"\x89HDF\r\n\x1a\nBroken file with correct signature" ) diff --git a/lib/iris/tests/test_io_init.py b/lib/iris/tests/test_io_init.py index d33b76ddeb..82da82cfa9 100644 --- a/lib/iris/tests/test_io_init.py +++ b/lib/iris/tests/test_io_init.py @@ -126,7 +126,7 @@ def test_format_picker(self): ] # test that each filespec is identified as the expected format - for (expected_format_name, file_spec) in test_specs: + for expected_format_name, file_spec in test_specs: test_path = tests.get_data_path(file_spec) with open(test_path, "rb") as test_file: a = iff.FORMAT_AGENT.get_spec(test_path, test_file) diff --git a/lib/iris/tests/test_merge.py b/lib/iris/tests/test_merge.py index c209d68da0..e53bbfb5f3 100644 --- a/lib/iris/tests/test_merge.py +++ b/lib/iris/tests/test_merge.py @@ -190,7 +190,7 @@ def setUp(self): ) def test__ndarray_ndarray(self): - for (lazy0, lazy1) in self.lazy_combos: + for lazy0, lazy1 in self.lazy_combos: cubes = iris.cube.CubeList() cubes.append(self._make_cube(0, dtype=self.dtype, lazy=lazy0)) cubes.append(self._make_cube(1, dtype=self.dtype, lazy=lazy1)) diff --git a/lib/iris/tests/test_netcdf.py b/lib/iris/tests/test_netcdf.py index 5017698a22..92e15a414a 100644 --- a/lib/iris/tests/test_netcdf.py +++ b/lib/iris/tests/test_netcdf.py @@ -313,9 +313,7 @@ def test_deferred_loading(self): cube[((0, 8, 4, 2, 14, 12),)][((0, 2, 4, 1),)], ("netcdf", "netcdf_deferred_tuple_1.cml"), ) - subcube = cube[((0, 8, 4, 2, 14, 12),)][((0, 2, 4, 1),)][ - (1, 3), - ] + subcube = cube[((0, 8, 4, 2, 14, 12),)][((0, 2, 4, 1),)][(1, 3),] self.assertCML(subcube, ("netcdf", "netcdf_deferred_tuple_2.cml")) # Consecutive mixture on same dimension. @@ -1417,7 +1415,6 @@ def test_process_flags(self): } for bits, descriptions in multiple_map.items(): - ll_cube = stock.lat_lon_cube() ll_cube.attributes["ukmo__process_flags"] = descriptions diff --git a/lib/iris/tests/test_nimrod.py b/lib/iris/tests/test_nimrod.py index a1d7bb298f..6d62623198 100644 --- a/lib/iris/tests/test_nimrod.py +++ b/lib/iris/tests/test_nimrod.py @@ -80,7 +80,8 @@ def test_huge_field_load(self): @tests.skip_data def test_load_kwarg(self): """Tests that the handle_metadata_errors kwarg is effective by setting it to - False with a file with known incomplete meta-data (missing ellipsoid).""" + False with a file with known incomplete meta-data (missing ellipsoid). + """ datafile = "u1096_ng_ek00_pressure_2km" with self.assertRaisesRegex( TranslationError, diff --git a/lib/iris/tests/test_pp_stash.py b/lib/iris/tests/test_pp_stash.py index b153aef0d4..42390ab2b3 100644 --- a/lib/iris/tests/test_pp_stash.py +++ b/lib/iris/tests/test_pp_stash.py @@ -86,7 +86,6 @@ def test_irregular_stash_str(self): ) def test_illegal_stash_str_range(self): - self.assertEqual(iris.fileformats.pp.STASH(0, 2, 3), "m??s02i003") self.assertNotEqual(iris.fileformats.pp.STASH(0, 2, 3), "m01s02i003") @@ -124,7 +123,7 @@ def test_illegal_stash_format(self): ("m01s02003", (1, 2, 3)), ) - for (test_value, reference) in test_values: + for test_value, reference in test_values: msg = "Expected STASH code .* {!r}".format(test_value) with self.assertRaisesRegex(ValueError, msg): test_value == iris.fileformats.pp.STASH(*reference) @@ -137,7 +136,7 @@ def test_illegal_stash_type(self): (["m01s02i003"], "m01s02i003"), ) - for (test_value, reference) in test_values: + for test_value, reference in test_values: msg = "Expected STASH code .* {!r}".format(test_value) with self.assertRaisesRegex(TypeError, msg): iris.fileformats.pp.STASH.from_msi(test_value) == reference diff --git a/lib/iris/tests/test_util.py b/lib/iris/tests/test_util.py index db182ae3f3..d8d5d73e95 100644 --- a/lib/iris/tests/test_util.py +++ b/lib/iris/tests/test_util.py @@ -161,7 +161,6 @@ def test_default_values(self): ) def test_trim_string_with_no_spaces(self): - clip_length = 200 no_space_string = "a" * 500 diff --git a/lib/iris/tests/unit/analysis/cartography/test_gridcell_angles.py b/lib/iris/tests/unit/analysis/cartography/test_gridcell_angles.py index 6b957baec6..810851362e 100644 --- a/lib/iris/tests/unit/analysis/cartography/test_gridcell_angles.py +++ b/lib/iris/tests/unit/analysis/cartography/test_gridcell_angles.py @@ -94,7 +94,6 @@ def _check_multiple_orientations_and_latitudes( atol_degrees=0.005, cellsize_degrees=1.0, ): - cube = _2d_multicells_testcube(cellsize_degrees=cellsize_degrees) # Calculate gridcell angles at each point. diff --git a/lib/iris/tests/unit/coords/test_AncillaryVariable.py b/lib/iris/tests/unit/coords/test_AncillaryVariable.py index 75b6250449..e5fc8fd28a 100644 --- a/lib/iris/tests/unit/coords/test_AncillaryVariable.py +++ b/lib/iris/tests/unit/coords/test_AncillaryVariable.py @@ -68,7 +68,7 @@ def setUp(self): self.setupTestArrays(masked=True) def test_lazyness_and_dtype_combinations(self): - for (ancill_var, data_lazyness) in data_all_dtypes_and_lazynesses( + for ancill_var, data_lazyness in data_all_dtypes_and_lazynesses( self, ): data = ancill_var.core_data() @@ -225,10 +225,9 @@ def test_dtypes(self): # floating dtype. # Check that dtypes remain the same in all cases, taking the dtypes # directly from the core data as we have no masking). - for (main_ancill_var, data_lazyness) in data_all_dtypes_and_lazynesses( + for main_ancill_var, data_lazyness in data_all_dtypes_and_lazynesses( self ): - sub_ancill_var = main_ancill_var[:2, 1] ancill_var_dtype = main_ancill_var.dtype @@ -250,10 +249,9 @@ def test_lazyness(self): # Index ancillary variables with real+lazy data, and either an int or # floating dtype. # Check that lazy data stays lazy and real stays real, in all cases. - for (main_ancill_var, data_lazyness) in data_all_dtypes_and_lazynesses( + for main_ancill_var, data_lazyness in data_all_dtypes_and_lazynesses( self ): - sub_ancill_var = main_ancill_var[:2, 1] msg = ( @@ -277,10 +275,9 @@ def test_lazyness(self): def test_real_data_copies(self): # Index ancillary variables with real+lazy data. # In all cases, check that any real arrays are copied by the indexing. - for (main_ancill_var, data_lazyness) in data_all_dtypes_and_lazynesses( + for main_ancill_var, data_lazyness in data_all_dtypes_and_lazynesses( self ): - sub_ancill_var = main_ancill_var[:2, 1] msg = ( @@ -308,10 +305,9 @@ def test_lazyness(self): # Copy ancillary variables with real+lazy data, and either an int or # floating dtype. # Check that lazy data stays lazy and real stays real, in all cases. - for (main_ancill_var, data_lazyness) in data_all_dtypes_and_lazynesses( + for main_ancill_var, data_lazyness in data_all_dtypes_and_lazynesses( self ): - ancill_var_dtype = main_ancill_var.dtype copied_ancill_var = main_ancill_var.copy() @@ -338,10 +334,9 @@ def test_lazyness(self): def test_realdata_copies(self): # Copy ancillary variables with real+lazy data. # In all cases, check that any real arrays are copies, not views. - for (main_ancill_var, data_lazyness) in data_all_dtypes_and_lazynesses( + for main_ancill_var, data_lazyness in data_all_dtypes_and_lazynesses( self ): - copied_ancill_var = main_ancill_var.copy() msg = ( @@ -520,79 +515,79 @@ def _check(self, result_ancill_var, expected_data, lazyness): self.assertEqualLazyArraysAndDtypes(expected_data, data) def test_add(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = ancill_var + 10 expected_data = orig_data + 10 self._check(result, expected_data, data_lazyness) def test_add_inplace(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: ancill_var += 10 expected_data = orig_data + 10 self._check(ancill_var, expected_data, data_lazyness) def test_right_add(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = 10 + ancill_var expected_data = 10 + orig_data self._check(result, expected_data, data_lazyness) def test_subtract(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = ancill_var - 10 expected_data = orig_data - 10 self._check(result, expected_data, data_lazyness) def test_subtract_inplace(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: ancill_var -= 10 expected_data = orig_data - 10 self._check(ancill_var, expected_data, data_lazyness) def test_right_subtract(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = 10 - ancill_var expected_data = 10 - orig_data self._check(result, expected_data, data_lazyness) def test_multiply(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = ancill_var * 10 expected_data = orig_data * 10 self._check(result, expected_data, data_lazyness) def test_multiply_inplace(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: ancill_var *= 10 expected_data = orig_data * 10 self._check(ancill_var, expected_data, data_lazyness) def test_right_multiply(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = 10 * ancill_var expected_data = 10 * orig_data self._check(result, expected_data, data_lazyness) def test_divide(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = ancill_var / 10 expected_data = orig_data / 10 self._check(result, expected_data, data_lazyness) def test_divide_inplace(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: ancill_var /= 10 expected_data = orig_data / 10 self._check(ancill_var, expected_data, data_lazyness) def test_right_divide(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = 10 / ancill_var expected_data = 10 / orig_data self._check(result, expected_data, data_lazyness) def test_negative(self): - for (ancill_var, orig_data, data_lazyness) in self.test_combinations: + for ancill_var, orig_data, data_lazyness in self.test_combinations: result = -ancill_var expected_data = -orig_data self._check(result, expected_data, data_lazyness) diff --git a/lib/iris/tests/unit/coords/test_AuxCoord.py b/lib/iris/tests/unit/coords/test_AuxCoord.py index e6cd8ac821..e5147659fc 100644 --- a/lib/iris/tests/unit/coords/test_AuxCoord.py +++ b/lib/iris/tests/unit/coords/test_AuxCoord.py @@ -370,7 +370,6 @@ def test_dtypes(self): points_type_name, bounds_type_name, ) in coords_all_dtypes_and_lazynesses(self, AuxCoord): - sub_coord = main_coord[:2, 1] coord_dtype = main_coord.dtype @@ -417,7 +416,6 @@ def test_lazyness(self): points_type_name, bounds_type_name, ) in coords_all_dtypes_and_lazynesses(self, AuxCoord): - sub_coord = main_coord[:2, 1] msg = ( @@ -463,7 +461,6 @@ def test_real_data_copies(self): points_lazyness, bounds_lazyness, ) in coords_all_dtypes_and_lazynesses(self, AuxCoord): - sub_coord = main_coord[:2, 1] msg = ( @@ -511,7 +508,6 @@ def test_lazyness(self): points_lazyness, bounds_lazyness, ) in coords_all_dtypes_and_lazynesses(self, AuxCoord): - coord_dtype = main_coord.dtype copied_coord = main_coord.copy() @@ -558,7 +554,6 @@ def test_realdata_copies(self): points_lazyness, bounds_lazyness, ) in coords_all_dtypes_and_lazynesses(self, AuxCoord): - copied_coord = main_coord.copy() msg = ( diff --git a/lib/iris/tests/unit/coords/test_Coord.py b/lib/iris/tests/unit/coords/test_Coord.py index dca6ed3c1b..72a48437ec 100644 --- a/lib/iris/tests/unit/coords/test_Coord.py +++ b/lib/iris/tests/unit/coords/test_Coord.py @@ -463,7 +463,6 @@ def test_lazy_nd_bounds_last(self): ) def test_lazy_nd_points_and_bounds(self): - self.setupTestArrays((3, 4)) coord = AuxCoord(self.pts_lazy, bounds=self.bds_lazy) @@ -520,7 +519,6 @@ def test_lazy_nd_noncontiguous_bounds_warning(self): coord.collapsed() def test_numeric_3_bounds(self): - points = np.array([2.0, 6.0, 4.0]) bounds = np.array([[1.0, 0.0, 3.0], [5.0, 4.0, 7.0], [3.0, 2.0, 5.0]]) @@ -544,7 +542,6 @@ def test_numeric_3_bounds(self): ) def test_lazy_3_bounds(self): - points = da.arange(3) * 2.0 bounds = da.arange(3 * 3).reshape(3, 3) diff --git a/lib/iris/tests/unit/coords/test_DimCoord.py b/lib/iris/tests/unit/coords/test_DimCoord.py index 4298b140ea..dd0ba48f3d 100644 --- a/lib/iris/tests/unit/coords/test_DimCoord.py +++ b/lib/iris/tests/unit/coords/test_DimCoord.py @@ -304,7 +304,6 @@ def test_dtypes(self): points_type_name, bounds_type_name, ) in coords_all_dtypes_and_lazynesses(self, DimCoord): - sub_coord = main_coord[:2] coord_dtype = main_coord.dtype @@ -404,7 +403,6 @@ def test_real_data_copies(self): points_lazyness, bounds_lazyness, ) in coords_all_dtypes_and_lazynesses(self, DimCoord): - sub_coord = main_coord[:2] msg = ( @@ -470,7 +468,6 @@ def test_realdata_readonly(self): points_type_name, bounds_type_name, ) in coords_all_dtypes_and_lazynesses(self, DimCoord): - copied_coord = main_coord.copy() copied_points = copied_coord.core_points() diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index 5d120a6982..8e9e00dce8 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -1962,6 +1962,7 @@ def _assert_lists_equal(self, items_a, items_b): a different order. """ + # Compare (and thus sort) by their *common* metadata. def sortkey(item): return BaseMetadata.from_metadata(item.metadata) diff --git a/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py b/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py index 538cecdc7d..03e2793fd9 100644 --- a/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py +++ b/lib/iris/tests/unit/experimental/ugrid/mesh/test_MeshCoord.py @@ -235,9 +235,7 @@ class Test__getitem__(tests.IrisTest): def test_slice_wholeslice_1tuple(self): # The only slicing case that we support, to enable cube slicing. meshcoord = sample_meshcoord() - meshcoord2 = meshcoord[ - :, - ] + meshcoord2 = meshcoord[:,] self.assertIsNot(meshcoord2, meshcoord) self.assertEqual(meshcoord2, meshcoord) # In this case, we should *NOT* copy the linked Mesh object. diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py index a8e44747dd..ffe00c8c19 100644 --- a/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py +++ b/lib/iris/tests/unit/fileformats/nc_load_rules/actions/test__miscellaneous.py @@ -127,7 +127,6 @@ def _make_testcase_cdl( include_cellmeasure=False, include_ancil=False, ): - phenom_extra_attrs_string = "" extra_vars_string = "" diff --git a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_dimension_coordinate.py b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_dimension_coordinate.py index b485937cb1..bc13975441 100644 --- a/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_dimension_coordinate.py +++ b/lib/iris/tests/unit/fileformats/nc_load_rules/helpers/test_build_dimension_coordinate.py @@ -229,7 +229,9 @@ def test_aux_coord_construction(self): warning_patch = mock.patch("warnings.warn") # Asserts must lie within context manager because of deferred loading. - with warning_patch, self.deferred_load_patch, self.get_cf_bounds_var_patch: + with ( + warning_patch + ), self.deferred_load_patch, self.get_cf_bounds_var_patch: build_dimension_coordinate(self.engine, self.cf_coord_var) # Test that expected coord is built and added to cube. diff --git a/lib/iris/tests/unit/fileformats/netcdf/test_Saver__ugrid.py b/lib/iris/tests/unit/fileformats/netcdf/test_Saver__ugrid.py index 575c852ece..18e86a9f57 100644 --- a/lib/iris/tests/unit/fileformats/netcdf/test_Saver__ugrid.py +++ b/lib/iris/tests/unit/fileformats/netcdf/test_Saver__ugrid.py @@ -1082,7 +1082,6 @@ def test_mesh_dim_names(self): ("dim invalid-name &%!", "dim_invalid_name____"), ] for given_name, expected_name in dim_names_tests: - mesh = make_mesh(mesh_kwargs={"face_dimension": given_name}) filepath = self.check_save_mesh(mesh) diff --git a/lib/iris/tests/unit/fileformats/pp/test_PPField.py b/lib/iris/tests/unit/fileformats/pp/test_PPField.py index 5e2bbcaa2c..316894ded1 100644 --- a/lib/iris/tests/unit/fileformats/pp/test_PPField.py +++ b/lib/iris/tests/unit/fileformats/pp/test_PPField.py @@ -44,7 +44,6 @@ class DummyPPField(PPField): - HEADER_DEFN = DUMMY_HEADER HEADER_DICT = dict(DUMMY_HEADER) diff --git a/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py b/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py index 62eb7ff019..e194e240c6 100644 --- a/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py +++ b/lib/iris/tests/unit/fileformats/pp_load_rules/test__all_other_rules.py @@ -211,7 +211,6 @@ def test_lbcode3x23(self): class TestLBTIMx2x_ZeroYears(TestField): - _spec = [ "lbtim", "lbcode", diff --git a/lib/iris/tests/unit/lazy_data/test_as_lazy_data.py b/lib/iris/tests/unit/lazy_data/test_as_lazy_data.py index 5aeebd6045..5f9dece153 100644 --- a/lib/iris/tests/unit/lazy_data/test_as_lazy_data.py +++ b/lib/iris/tests/unit/lazy_data/test_as_lazy_data.py @@ -68,7 +68,7 @@ def test_chunk_size_limiting(self): ((11, 2, 1011, 1022), (5, 2, 1011, 1022)), ] err_fmt = "Result of optimising chunks {} was {}, expected {}" - for (shape, expected) in given_shapes_and_resulting_chunks: + for shape, expected in given_shapes_and_resulting_chunks: chunks = _optimum_chunksize( shape, shape, limit=self.FIXED_CHUNKSIZE_LIMIT ) @@ -86,7 +86,7 @@ def test_chunk_size_expanding(self): ((3, 300, 200), (117, 300, 1000), (39, 300, 1000)), ] err_fmt = "Result of optimising shape={};chunks={} was {}, expected {}" - for (shape, fullshape, expected) in given_shapes_and_resulting_chunks: + for shape, fullshape, expected in given_shapes_and_resulting_chunks: chunks = _optimum_chunksize( chunks=shape, shape=fullshape, limit=self.FIXED_CHUNKSIZE_LIMIT ) diff --git a/lib/iris/tests/unit/merge/test_ProtoCube.py b/lib/iris/tests/unit/merge/test_ProtoCube.py index 625290ad24..0fca726b28 100644 --- a/lib/iris/tests/unit/merge/test_ProtoCube.py +++ b/lib/iris/tests/unit/merge/test_ProtoCube.py @@ -289,7 +289,6 @@ def test_noise(self): class Test_register__CoordSig_general(_MergeTest, tests.IrisTest): - _mergetest_type = "coord" def setUp(self): @@ -444,7 +443,6 @@ def test_coord_system(self): class Test_register__CoordSig_scalar(_MergeTest_coordprops, tests.IrisTest): - _mergetest_type = "aux_coords (scalar)" def setUp(self): @@ -486,7 +484,6 @@ def test_dims(self): class Test_register__CoordSig_dim(_MergeTest_coordprops_vect, tests.IrisTest): - _mergetest_type = "dim_coords" _coord_typename = "dim_coord" @@ -515,7 +512,6 @@ def test_circular(self): class Test_register__CoordSig_aux(_MergeTest_coordprops_vect, tests.IrisTest): - _mergetest_type = "aux_coords (non-scalar)" _coord_typename = "aux_coord" diff --git a/lib/iris/util.py b/lib/iris/util.py index 1cf41e6fb6..9e0db9e66e 100644 --- a/lib/iris/util.py +++ b/lib/iris/util.py @@ -735,7 +735,6 @@ def _build_full_slice_given_keys(keys, ndim): for i, key in enumerate(keys): if key is Ellipsis: - # replace any subsequent Ellipsis objects in keys with # slice(None, None) as per Numpy keys = keys[:i] + tuple(