diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4bd21466dc..b609c47ddb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: # Don't commit to master branch. - id: no-commit-to-branch - repo: https://github.com/psf/black - rev: '19.10b0' + rev: '20.8b1' hooks: - id: black # Force black to run on whole repo, using settings from pyproject.toml diff --git a/docs/iris/gallery_code/general/plot_custom_file_loading.py b/docs/iris/gallery_code/general/plot_custom_file_loading.py index 0d130374a7..b96e152bf8 100644 --- a/docs/iris/gallery_code/general/plot_custom_file_loading.py +++ b/docs/iris/gallery_code/general/plot_custom_file_loading.py @@ -314,7 +314,9 @@ def main(): # draw contour levels for the data (the top level is just a catch-all) levels = (0.0002, 0.002, 0.004, 1e10) cs = iplt.contourf( - cube, levels=levels, colors=("#80ffff", "#939598", "#e00404"), + cube, + levels=levels, + colors=("#80ffff", "#939598", "#e00404"), ) # draw a black outline at the lowest contour to highlight affected areas diff --git a/lib/iris/_concatenate.py b/lib/iris/_concatenate.py index 6bda3aa274..b1c8364879 100644 --- a/lib/iris/_concatenate.py +++ b/lib/iris/_concatenate.py @@ -161,7 +161,12 @@ def name(self): return self.defn.name() -class _OtherMetaData(namedtuple("OtherMetaData", ["defn", "dims"],)): +class _OtherMetaData( + namedtuple( + "OtherMetaData", + ["defn", "dims"], + ) +): """ Container for the metadata that defines a cell measure or ancillary variable. diff --git a/lib/iris/analysis/_area_weighted.py b/lib/iris/analysis/_area_weighted.py index 6872800215..98734fb068 100644 --- a/lib/iris/analysis/_area_weighted.py +++ b/lib/iris/analysis/_area_weighted.py @@ -55,8 +55,10 @@ def __init__(self, src_grid_cube, target_grid_cube, mdtol=1): self._mdtol = mdtol # Store regridding information - _regrid_info = eregrid._regrid_area_weighted_rectilinear_src_and_grid__prepare( - src_grid_cube, target_grid_cube + _regrid_info = ( + eregrid._regrid_area_weighted_rectilinear_src_and_grid__prepare( + src_grid_cube, target_grid_cube + ) ) ( src_x, diff --git a/lib/iris/analysis/_regrid.py b/lib/iris/analysis/_regrid.py index 1036c3028d..7063fdef43 100644 --- a/lib/iris/analysis/_regrid.py +++ b/lib/iris/analysis/_regrid.py @@ -480,11 +480,15 @@ def __call__(self, src): for slice_cube in src.slices(sx): if self._regrid_info is None: # Calculate the basic regrid info just once. - self._regrid_info = _regrid_weighted_curvilinear_to_rectilinear__prepare( - slice_cube, self.weights, self._target_cube + self._regrid_info = ( + _regrid_weighted_curvilinear_to_rectilinear__prepare( + slice_cube, self.weights, self._target_cube + ) + ) + slice_result = ( + _regrid_weighted_curvilinear_to_rectilinear__perform( + slice_cube, self._regrid_info ) - slice_result = _regrid_weighted_curvilinear_to_rectilinear__perform( - slice_cube, self._regrid_info ) result_slices.append(slice_result) result = result_slices.merge_cube() diff --git a/lib/iris/analysis/calculus.py b/lib/iris/analysis/calculus.py index a7ce385932..8b2b95f7c8 100644 --- a/lib/iris/analysis/calculus.py +++ b/lib/iris/analysis/calculus.py @@ -623,10 +623,14 @@ def curl(i_cube, j_cube, k_cube=None): # (d/dtheta (i_cube * sin(lat)) - d_j_cube_dphi) # phi_cmpt = 1/r * ( d/dr (r * j_cube) - d_k_cube_dtheta) # theta_cmpt = 1/r * ( 1/cos(lat) * d_k_cube_dphi - d/dr (r * i_cube) - if y_coord.name() not in [ - "latitude", - "grid_latitude", - ] or x_coord.name() not in ["longitude", "grid_longitude"]: + if ( + y_coord.name() + not in [ + "latitude", + "grid_latitude", + ] + or x_coord.name() not in ["longitude", "grid_longitude"] + ): raise ValueError( "Expecting latitude as the y coord and " "longitude as the x coord for spherical curl." diff --git a/lib/iris/common/resolve.py b/lib/iris/common/resolve.py index 34c4333579..268ea723f3 100644 --- a/lib/iris/common/resolve.py +++ b/lib/iris/common/resolve.py @@ -37,7 +37,8 @@ ) _CategoryItems = namedtuple( - "CategoryItems", ["items_dim", "items_aux", "items_scalar"], + "CategoryItems", + ["items_dim", "items_aux", "items_scalar"], ) _DimCoverage = namedtuple( @@ -50,7 +51,8 @@ _PreparedFactory = namedtuple("PreparedFactory", ["container", "dependencies"]) _PreparedItem = namedtuple( - "PreparedItem", ["metadata", "points", "bounds", "dims", "container"], + "PreparedItem", + ["metadata", "points", "bounds", "dims", "container"], ) _PreparedMetadata = namedtuple("PreparedMetadata", ["combined", "src", "tgt"]) diff --git a/lib/iris/cube.py b/lib/iris/cube.py index 0a27c2f0e7..326885fda7 100644 --- a/lib/iris/cube.py +++ b/lib/iris/cube.py @@ -3647,8 +3647,8 @@ def __eq__(self, other): # having checked the metadata, now check the coordinates if result: - coord_compares = iris.analysis._dimensional_metadata_comparison( - self, other + coord_compares = ( + iris.analysis._dimensional_metadata_comparison(self, other) ) # if there are any coordinates which are not equal result = not ( @@ -3658,7 +3658,9 @@ def __eq__(self, other): if result: cm_compares = iris.analysis._dimensional_metadata_comparison( - self, other, object_get=Cube.cell_measures, + self, + other, + object_get=Cube.cell_measures, ) # if there are any cell measures which are not equal result = not ( @@ -3668,7 +3670,9 @@ def __eq__(self, other): if result: av_compares = iris.analysis._dimensional_metadata_comparison( - self, other, object_get=Cube.ancillary_variables, + self, + other, + object_get=Cube.ancillary_variables, ) # if there are any ancillary variables which are not equal result = not ( diff --git a/lib/iris/fileformats/_ff.py b/lib/iris/fileformats/_ff.py index 08f3e3f246..cd153fb7da 100644 --- a/lib/iris/fileformats/_ff.py +++ b/lib/iris/fileformats/_ff.py @@ -42,23 +42,140 @@ ("model_version", (12,)), ("obs_file_type", (14,)), ("last_fieldop_type", (15,)), - ("first_validity_time", (21, 22, 23, 24, 25, 26, 27,)), - ("last_validity_time", (28, 29, 30, 31, 32, 33, 34,)), - ("misc_validity_time", (35, 36, 37, 38, 39, 40, 41,)), - ("integer_constants", (100, 101,)), - ("real_constants", (105, 106,)), - ("level_dependent_constants", (110, 111, 112,)), - ("row_dependent_constants", (115, 116, 117,)), - ("column_dependent_constants", (120, 121, 122,)), - ("fields_of_constants", (125, 126, 127,)), - ("extra_constants", (130, 131,)), - ("temp_historyfile", (135, 136,)), - ("compressed_field_index1", (140, 141,)), - ("compressed_field_index2", (142, 143,)), - ("compressed_field_index3", (144, 145,)), - ("lookup_table", (150, 151, 152,)), + ( + "first_validity_time", + ( + 21, + 22, + 23, + 24, + 25, + 26, + 27, + ), + ), + ( + "last_validity_time", + ( + 28, + 29, + 30, + 31, + 32, + 33, + 34, + ), + ), + ( + "misc_validity_time", + ( + 35, + 36, + 37, + 38, + 39, + 40, + 41, + ), + ), + ( + "integer_constants", + ( + 100, + 101, + ), + ), + ( + "real_constants", + ( + 105, + 106, + ), + ), + ( + "level_dependent_constants", + ( + 110, + 111, + 112, + ), + ), + ( + "row_dependent_constants", + ( + 115, + 116, + 117, + ), + ), + ( + "column_dependent_constants", + ( + 120, + 121, + 122, + ), + ), + ( + "fields_of_constants", + ( + 125, + 126, + 127, + ), + ), + ( + "extra_constants", + ( + 130, + 131, + ), + ), + ( + "temp_historyfile", + ( + 135, + 136, + ), + ), + ( + "compressed_field_index1", + ( + 140, + 141, + ), + ), + ( + "compressed_field_index2", + ( + 142, + 143, + ), + ), + ( + "compressed_field_index3", + ( + 144, + 145, + ), + ), + ( + "lookup_table", + ( + 150, + 151, + 152, + ), + ), ("total_prognostic_fields", (153,)), - ("data", (160, 161, 162,)), + ( + "data", + ( + 160, + 161, + 162, + ), + ), ] # Offset value to convert from UM_FIXED_LENGTH_HEADER positions to diff --git a/lib/iris/fileformats/cf.py b/lib/iris/fileformats/cf.py index 75f328a80e..134438e29c 100644 --- a/lib/iris/fileformats/cf.py +++ b/lib/iris/fileformats/cf.py @@ -45,7 +45,12 @@ # NetCDF variable attributes handled by the netCDF4 module and # therefore automatically classed as "used" attributes. _CF_ATTRS_IGNORE = set( - ["_FillValue", "add_offset", "missing_value", "scale_factor",] + [ + "_FillValue", + "add_offset", + "missing_value", + "scale_factor", + ] ) #: Supported dimensionless vertical coordinate reference surface/phemomenon diff --git a/lib/iris/fileformats/name_loaders.py b/lib/iris/fileformats/name_loaders.py index 0464eb37ed..20c3974b59 100644 --- a/lib/iris/fileformats/name_loaders.py +++ b/lib/iris/fileformats/name_loaders.py @@ -489,7 +489,9 @@ def _generate_cubes( circular = False if coord.name == "flight_level": icoord = DimCoord( - points=pts, units=coord_units, long_name=long_name, + points=pts, + units=coord_units, + long_name=long_name, ) else: icoord = DimCoord( diff --git a/lib/iris/fileformats/netcdf.py b/lib/iris/fileformats/netcdf.py index 993214baa4..d0c3a3c534 100644 --- a/lib/iris/fileformats/netcdf.py +++ b/lib/iris/fileformats/netcdf.py @@ -1066,7 +1066,7 @@ def write( `chunksizes` and `endian` keywords are silently ignored for netCDF 3 files that do not use HDF5. - """ + """ if unlimited_dimensions is None: unlimited_dimensions = [] diff --git a/lib/iris/fileformats/nimrod_load_rules.py b/lib/iris/fileformats/nimrod_load_rules.py index 4cf8755bb9..f7f1ec07d1 100644 --- a/lib/iris/fileformats/nimrod_load_rules.py +++ b/lib/iris/fileformats/nimrod_load_rules.py @@ -417,7 +417,8 @@ def coord_system(field, handle_metadata_errors): "Plotting and reprojection may be impaired." ) coord_sys = iris.coord_systems.TransverseMercator( - *crs_args, iris.coord_systems.GeogCS(**ellipsoid), + *crs_args, + iris.coord_systems.GeogCS(**ellipsoid), ) elif field.horizontal_grid_type == 1: coord_sys = iris.coord_systems.GeogCS(**ellipsoid) @@ -456,7 +457,10 @@ def horizontal_grid(cube, field, handle_metadata_errors): dtype=np.float32, ) x_coord = DimCoord( - points, standard_name=x_coord_name, units=units_name, coord_system=crs, + points, + standard_name=x_coord_name, + units=units_name, + coord_system=crs, ) cube.add_dim_coord(x_coord, 1) points = np.linspace( @@ -467,7 +471,10 @@ def horizontal_grid(cube, field, handle_metadata_errors): dtype=np.float32, ) y_coord = DimCoord( - points, standard_name=y_coord_name, units=units_name, coord_system=crs, + points, + standard_name=y_coord_name, + units=units_name, + coord_system=crs, ) cube.add_dim_coord(y_coord, 0) diff --git a/lib/iris/fileformats/pp.py b/lib/iris/fileformats/pp.py index f1bd51f645..911e10ef14 100644 --- a/lib/iris/fileformats/pp.py +++ b/lib/iris/fileformats/pp.py @@ -105,10 +105,37 @@ ("lbproj", (31,)), ("lbtyp", (32,)), ("lblev", (33,)), - ("lbrsvd", (34, 35, 36, 37,)), + ( + "lbrsvd", + ( + 34, + 35, + 36, + 37, + ), + ), ("lbsrce", (38,)), - ("lbuser", (39, 40, 41, 42, 43, 44, 45,)), - ("brsvd", (46, 47, 48, 49,)), + ( + "lbuser", + ( + 39, + 40, + 41, + 42, + 43, + 44, + 45, + ), + ), + ( + "brsvd", + ( + 46, + 47, + 48, + 49, + ), + ), ("bdatum", (50,)), ("bacc", (51,)), ("blev", (52,)), @@ -163,10 +190,37 @@ ("lbproj", (31,)), ("lbtyp", (32,)), ("lblev", (33,)), - ("lbrsvd", (34, 35, 36, 37,)), + ( + "lbrsvd", + ( + 34, + 35, + 36, + 37, + ), + ), ("lbsrce", (38,)), - ("lbuser", (39, 40, 41, 42, 43, 44, 45,)), - ("brsvd", (46, 47, 48, 49,)), + ( + "lbuser", + ( + 39, + 40, + 41, + 42, + 43, + 44, + 45, + ), + ), + ( + "brsvd", + ( + 46, + 47, + 48, + 49, + ), + ), ("bdatum", (50,)), ("bacc", (51,)), ("blev", (52,)), diff --git a/lib/iris/plot.py b/lib/iris/plot.py index b489bba732..d0a42ca429 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -351,7 +351,12 @@ def _check_bounds_contiguity_and_mask(coord, data, atol=None, rtol=None): ) not_masked_at_discontiguity_along_y = np.any( - np.logical_and(mask_invert[:-1,], diffs_along_y) + np.logical_and( + mask_invert[ + :-1, + ], + diffs_along_y, + ) ) not_masked_at_discontiguity = ( diff --git a/lib/iris/tests/test_cdm.py b/lib/iris/tests/test_cdm.py index bbaae1a8de..ee26a82652 100644 --- a/lib/iris/tests/test_cdm.py +++ b/lib/iris/tests/test_cdm.py @@ -1135,7 +1135,13 @@ def assert_is_not_lazy(self, cube): self.assertFalse(cube.has_lazy_data()) def test_slices(self): - lat_cube = next(self.cube.slices(["grid_latitude",])) + lat_cube = next( + self.cube.slices( + [ + "grid_latitude", + ] + ) + ) self.assert_is_lazy(lat_cube) self.assert_is_lazy(self.cube) @@ -1459,7 +1465,11 @@ def test_coord_conversion(self): # List of string and unicode self.assertEqual( - len(cube._as_list_of_coords(["grid_longitude", "grid_latitude"],)), + len( + cube._as_list_of_coords( + ["grid_longitude", "grid_latitude"], + ) + ), 2, ) diff --git a/lib/iris/tests/test_merge.py b/lib/iris/tests/test_merge.py index 1e6aff8666..8336a5e68d 100644 --- a/lib/iris/tests/test_merge.py +++ b/lib/iris/tests/test_merge.py @@ -1038,11 +1038,13 @@ def _makecube(self, y, cm=False, av=False): cube.add_aux_coord(iris.coords.DimCoord(y, long_name="y")) if cm: cube.add_cell_measure( - iris.coords.CellMeasure([1, 1], long_name="foo"), 0, + iris.coords.CellMeasure([1, 1], long_name="foo"), + 0, ) if av: cube.add_ancillary_variable( - iris.coords.AncillaryVariable([1, 1], long_name="bar"), 0, + iris.coords.AncillaryVariable([1, 1], long_name="bar"), + 0, ) return cube diff --git a/lib/iris/tests/test_netcdf.py b/lib/iris/tests/test_netcdf.py index 13a03a76c3..e824813a49 100644 --- a/lib/iris/tests/test_netcdf.py +++ b/lib/iris/tests/test_netcdf.py @@ -425,11 +425,15 @@ def test_deferred_loading(self): # Consecutive tuple index on same dimension. self.assertCML( - cube[(0, 8, 4, 2, 14, 12),], + cube[ + (0, 8, 4, 2, 14, 12), + ], ("netcdf", "netcdf_deferred_tuple_0.cml"), ) self.assertCML( - cube[(0, 8, 4, 2, 14, 12),][(0, 2, 4, 1),], + 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),][ @@ -439,11 +443,15 @@ def test_deferred_loading(self): # Consecutive mixture on same dimension. self.assertCML( - cube[0:20:2][(9, 5, 8, 0),][3], + cube[0:20:2][ + (9, 5, 8, 0), + ][3], ("netcdf", "netcdf_deferred_mix_0.cml"), ) self.assertCML( - cube[(2, 7, 3, 4, 5, 0, 9, 10),][2:6][3], + cube[(2, 7, 3, 4, 5, 0, 9, 10),][ + 2:6 + ][3], ("netcdf", "netcdf_deferred_mix_0.cml"), ) self.assertCML( diff --git a/lib/iris/tests/test_nimrod.py b/lib/iris/tests/test_nimrod.py index bcb9255dca..211161118e 100644 --- a/lib/iris/tests/test_nimrod.py +++ b/lib/iris/tests/test_nimrod.py @@ -73,7 +73,14 @@ def test_huge_field_load(self): "probability_fields", }: cube = iris.load( - tests.get_data_path(("NIMROD", "uk2km", "cutouts", datafile,)) + tests.get_data_path( + ( + "NIMROD", + "uk2km", + "cutouts", + datafile, + ) + ) ) self.assertCML(cube, ("nimrod", f"{datafile}.cml")) @@ -87,7 +94,14 @@ def test_load_kwarg(self): "Ellipsoid not supported, proj_biaxial_ellipsoid:-32767, horizontal_grid_type:0", ): with open( - tests.get_data_path(("NIMROD", "uk2km", "cutouts", datafile,)), + tests.get_data_path( + ( + "NIMROD", + "uk2km", + "cutouts", + datafile, + ) + ), "rb", ) as infile: iris.fileformats.nimrod_load_rules.run( diff --git a/lib/iris/tests/test_pp_cf.py b/lib/iris/tests/test_pp_cf.py index 9760096d19..37b2701353 100644 --- a/lib/iris/tests/test_pp_cf.py +++ b/lib/iris/tests/test_pp_cf.py @@ -88,7 +88,12 @@ def _test_file(self, name): fname_name = name self.assertCML( - cubes, self._ref_dir + ("from_pp", fname_name + ".cml",) + cubes, + self._ref_dir + + ( + "from_pp", + fname_name + ".cml", + ), ) # 2) Save the Cube and check the netCDF diff --git a/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py b/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py index 18312737fe..ce573b7106 100644 --- a/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py +++ b/lib/iris/tests/unit/analysis/area_weighted/test_AreaWeightedRegridder.py @@ -46,8 +46,10 @@ def extract_grid(self, cube): def check_mdtol(self, mdtol=None): src_grid, target_grid = self.grids() # Get _regrid_info result - _regrid_info = eregrid._regrid_area_weighted_rectilinear_src_and_grid__prepare( - src_grid, target_grid + _regrid_info = ( + eregrid._regrid_area_weighted_rectilinear_src_and_grid__prepare( + src_grid, target_grid + ) ) self.assertEqual(len(_regrid_info), 9) with mock.patch( diff --git a/lib/iris/tests/unit/common/lenient/test__Lenient.py b/lib/iris/tests/unit/common/lenient/test__Lenient.py index d6bc2882d6..219dcf335d 100644 --- a/lib/iris/tests/unit/common/lenient/test__Lenient.py +++ b/lib/iris/tests/unit/common/lenient/test__Lenient.py @@ -52,7 +52,10 @@ def service2(): services = (service1, service2) lenient = _Lenient(*services) self.expected.update( - {_qualname(service1): True, _qualname(service2): True,} + { + _qualname(service1): True, + _qualname(service2): True, + } ) self.assertEqual(self.expected, lenient.__dict__) diff --git a/lib/iris/tests/unit/common/metadata/test_AncillaryVariableMetadata.py b/lib/iris/tests/unit/common/metadata/test_AncillaryVariableMetadata.py index 0e2ca52c47..6773d72474 100644 --- a/lib/iris/tests/unit/common/metadata/test_AncillaryVariableMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_AncillaryVariableMetadata.py @@ -78,7 +78,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, + BaseMetadata.__eq__.__doc__, + self.cls.__eq__.__doc__, ) def test_lenient_service(self): @@ -205,7 +206,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.combine.__doc__, self.cls.combine.__doc__, + BaseMetadata.combine.__doc__, + self.cls.combine.__doc__, ) def test_lenient_service(self): @@ -324,7 +326,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.difference.__doc__, self.cls.difference.__doc__, + BaseMetadata.difference.__doc__, + self.cls.difference.__doc__, ) def test_lenient_service(self): diff --git a/lib/iris/tests/unit/common/metadata/test_BaseMetadata.py b/lib/iris/tests/unit/common/metadata/test_BaseMetadata.py index eb0ee9d659..71fabe6c73 100644 --- a/lib/iris/tests/unit/common/metadata/test_BaseMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_BaseMetadata.py @@ -310,7 +310,9 @@ def test_attributes(self): rmetadata = self.cls(**right) return_value = sentinel.return_value with mock.patch.object( - self.cls, "_combine_lenient_attributes", return_value=return_value, + self.cls, + "_combine_lenient_attributes", + return_value=return_value, ) as mocker: lmetadata = self.cls(**left) result = lmetadata._combine_lenient(rmetadata) @@ -656,7 +658,9 @@ def test_attributes(self): right["attributes"] = rdict rmetadata = self.cls(**right) with mock.patch.object( - self.cls, "_compare_lenient_attributes", return_value=True, + self.cls, + "_compare_lenient_attributes", + return_value=True, ) as mocker: lmetadata = self.cls(**left) self.assertTrue(lmetadata._compare_lenient(rmetadata)) diff --git a/lib/iris/tests/unit/common/metadata/test_CellMeasureMetadata.py b/lib/iris/tests/unit/common/metadata/test_CellMeasureMetadata.py index 6044fbc628..f436b630a3 100644 --- a/lib/iris/tests/unit/common/metadata/test_CellMeasureMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_CellMeasureMetadata.py @@ -83,7 +83,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, + BaseMetadata.__eq__.__doc__, + self.cls.__eq__.__doc__, ) def test_lenient_service(self): @@ -251,7 +252,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.combine.__doc__, self.cls.combine.__doc__, + BaseMetadata.combine.__doc__, + self.cls.combine.__doc__, ) def test_lenient_service(self): @@ -418,7 +420,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.difference.__doc__, self.cls.difference.__doc__, + BaseMetadata.difference.__doc__, + self.cls.difference.__doc__, ) def test_lenient_service(self): diff --git a/lib/iris/tests/unit/common/metadata/test_CoordMetadata.py b/lib/iris/tests/unit/common/metadata/test_CoordMetadata.py index c37d33c62f..27e9e9b97a 100644 --- a/lib/iris/tests/unit/common/metadata/test_CoordMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_CoordMetadata.py @@ -89,7 +89,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, + BaseMetadata.__eq__.__doc__, + self.cls.__eq__.__doc__, ) def test_lenient_service(self): @@ -270,7 +271,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.combine.__doc__, self.cls.combine.__doc__, + BaseMetadata.combine.__doc__, + self.cls.combine.__doc__, ) def test_lenient_service(self): @@ -466,7 +468,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.difference.__doc__, self.cls.difference.__doc__, + BaseMetadata.difference.__doc__, + self.cls.difference.__doc__, ) def test_lenient_service(self): diff --git a/lib/iris/tests/unit/common/metadata/test_CubeMetadata.py b/lib/iris/tests/unit/common/metadata/test_CubeMetadata.py index 1636f85189..a34ad805e2 100644 --- a/lib/iris/tests/unit/common/metadata/test_CubeMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_CubeMetadata.py @@ -107,7 +107,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, + BaseMetadata.__eq__.__doc__, + self.cls.__eq__.__doc__, ) def test_lenient_service(self): @@ -275,7 +276,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.combine.__doc__, self.cls.combine.__doc__, + BaseMetadata.combine.__doc__, + self.cls.combine.__doc__, ) def test_lenient_service(self): @@ -442,7 +444,8 @@ def setUp(self): def test_wraps_docstring(self): self.assertEqual( - BaseMetadata.difference.__doc__, self.cls.difference.__doc__, + BaseMetadata.difference.__doc__, + self.cls.difference.__doc__, ) def test_lenient_service(self): diff --git a/lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py b/lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py index bfaeae2daf..17c930dec1 100644 --- a/lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py +++ b/lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py @@ -40,12 +40,20 @@ def test___eq__(self): self.assertEqual(left, values) def test___eq___numpy(self): - values = dict(one=np.arange(1), two=np.arange(2), three=np.arange(3),) + values = dict( + one=np.arange(1), + two=np.arange(2), + three=np.arange(3), + ) left = LimitedAttributeDict(**values) right = LimitedAttributeDict(**values) self.assertEqual(left, right) self.assertEqual(left, values) - values = dict(one=np.arange(1), two=np.arange(1), three=np.arange(1),) + values = dict( + one=np.arange(1), + two=np.arange(1), + three=np.arange(1), + ) left = LimitedAttributeDict(dict(one=0, two=0, three=0)) right = LimitedAttributeDict(**values) self.assertEqual(left, right) diff --git a/lib/iris/tests/unit/coords/test_AncillaryVariable.py b/lib/iris/tests/unit/coords/test_AncillaryVariable.py index b59788fb6c..b39e51cd68 100644 --- a/lib/iris/tests/unit/coords/test_AncillaryVariable.py +++ b/lib/iris/tests/unit/coords/test_AncillaryVariable.py @@ -441,7 +441,8 @@ def test_non_time_values(self): "attributes={'notes': 'Measured from sea level'})" ) self.assertEqual( - expected, ancillary_var.__str__(), + expected, + ancillary_var.__str__(), ) def test_time_values(self): @@ -457,7 +458,8 @@ def test_time_values(self): "long_name='time of previous valid detection')" ) self.assertEqual( - expected, ancillary_var.__str__(), + expected, + ancillary_var.__str__(), ) @@ -478,7 +480,8 @@ def test_non_time_values(self): "attributes={'notes': 'Measured from sea level'})" ) self.assertEqual( - expected, ancillary_var.__repr__(), + expected, + ancillary_var.__repr__(), ) def test_time_values(self): diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index 3b98be6454..6aa3c239fb 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -2004,7 +2004,8 @@ def setUp(self): np.arange(6).reshape(2, 3), long_name="area" ) self.b_cell_measure = CellMeasure( - np.arange(6).reshape(2, 3), long_name="other_area", + np.arange(6).reshape(2, 3), + long_name="other_area", ) cube.add_cell_measure(a_cell_measure, [0, 1]) cube.add_cell_measure(self.b_cell_measure, [0, 1]) @@ -2155,7 +2156,9 @@ def setUp(self): z_coord = AuxCoord(points=np.arange(6).reshape(2, 3), long_name="z") cube.add_aux_coord(z_coord, [0, 1]) self.a_cell_measure = CellMeasure( - np.arange(6).reshape(2, 3), long_name="area", units="m2", + np.arange(6).reshape(2, 3), + long_name="area", + units="m2", ) cube.add_cell_measure(self.a_cell_measure, [0, 1]) self.cube = cube @@ -2257,7 +2260,8 @@ def test_aux_coords(self): def test_cell_measures(self): area_cm = CellMeasure( - np.arange(12).reshape(3, 4), long_name="area of cells", + np.arange(12).reshape(3, 4), + long_name="area of cells", ) self.cube.add_cell_measure(area_cm, (0, 2)) self.cube.transpose() diff --git a/lib/iris/tests/unit/fileformats/nimrod_load_rules/test_units.py b/lib/iris/tests/unit/fileformats/nimrod_load_rules/test_units.py index cf6dd8cdb3..0cc4d9105f 100644 --- a/lib/iris/tests/unit/fileformats/nimrod_load_rules/test_units.py +++ b/lib/iris/tests/unit/fileformats/nimrod_load_rules/test_units.py @@ -36,7 +36,9 @@ def setUp(self): self.cube = Cube(np.ones((3, 3), dtype=np.float32)) def _call_units( - self, data=None, units_str=None, + self, + data=None, + units_str=None, ): if data is not None: self.cube.data = data @@ -106,7 +108,8 @@ def test_ug_per_m3_units(self): def test_g_per_kg(self): with mock.patch("warnings.warn") as warn: self._call_units( - data=((np.ones_like(self.cube.data) * 1000)), units_str="g/Kg", + data=((np.ones_like(self.cube.data) * 1000)), + units_str="g/Kg", ) self.assertEqual(warn.call_count, 0) self.assertEqual(self.cube.units, "kg/kg") @@ -117,7 +120,9 @@ def test_g_per_kg(self): def test_unit_expection_dictionary(self): with mock.patch("warnings.warn") as warn: - self._call_units(units_str="mb",) + self._call_units( + units_str="mb", + ) self.assertEqual(warn.call_count, 0) self.assertEqual(self.cube.units, "hPa") self.assertArrayAlmostEqual( @@ -127,7 +132,9 @@ def test_unit_expection_dictionary(self): def test_per_second(self): with mock.patch("warnings.warn") as warn: - self._call_units(units_str="/s",) + self._call_units( + units_str="/s", + ) self.assertEqual(warn.call_count, 0) self.assertEqual(self.cube.units, "s^-1") self.assertArrayAlmostEqual( @@ -137,7 +144,9 @@ def test_per_second(self): def test_unhandled_unit(self): with mock.patch("warnings.warn") as warn: - self._call_units(units_str="kittens",) + self._call_units( + units_str="kittens", + ) self.assertEqual(warn.call_count, 1) self.assertEqual(self.cube.units, "") self.assertArrayAlmostEqual( diff --git a/lib/iris/tests/unit/fileformats/pp/test_PPField.py b/lib/iris/tests/unit/fileformats/pp/test_PPField.py index 52c6996622..a822351573 100644 --- a/lib/iris/tests/unit/fileformats/pp/test_PPField.py +++ b/lib/iris/tests/unit/fileformats/pp/test_PPField.py @@ -35,7 +35,18 @@ ("lbext", (19,)), ("lbpack", (20,)), ("dummy5", (21, 37)), - ("lbuser", (38, 39, 40, 41, 42, 43, 44,)), + ( + "lbuser", + ( + 38, + 39, + 40, + 41, + 42, + 43, + 44, + ), + ), ("brsvd", (45, 46, 47, 48)), ("bdatum", (49,)), ("dummy6", (50, 61)), diff --git a/lib/iris/tests/unit/fileformats/pp/test_save.py b/lib/iris/tests/unit/fileformats/pp/test_save.py index 0ae1f7dd03..983b0fe437 100644 --- a/lib/iris/tests/unit/fileformats/pp/test_save.py +++ b/lib/iris/tests/unit/fileformats/pp/test_save.py @@ -324,10 +324,14 @@ def _get_single_time_cube(set_time_mean=False): cube.remove_coord("time") cube.remove_coord("forecast_period") tc = DimCoord( - points=[15,], + points=[ + 15, + ], standard_name="time", units=cf_units.Unit("days since epoch", calendar="360_day"), - bounds=[[0, 30],], + bounds=[ + [0, 30], + ], ) cube.add_dim_coord(tc, 0) if set_time_mean: diff --git a/lib/iris/tests/unit/fileformats/um/fast_load_structured_fields/test_BasicFieldCollation.py b/lib/iris/tests/unit/fileformats/um/fast_load_structured_fields/test_BasicFieldCollation.py index c3c75af19b..8619cfaf70 100644 --- a/lib/iris/tests/unit/fileformats/um/fast_load_structured_fields/test_BasicFieldCollation.py +++ b/lib/iris/tests/unit/fileformats/um/fast_load_structured_fields/test_BasicFieldCollation.py @@ -222,7 +222,12 @@ def test(self): for test_tuple in test_date_tuples ] # Check all values are distinct. - self.assertEqual(len(test_date_ints), len(set(test_date_ints),)) + self.assertEqual( + len(test_date_ints), + len( + set(test_date_ints), + ), + ) # Check all values are in order. self.assertEqual(test_date_ints, sorted(test_date_ints)) diff --git a/lib/iris/tests/unit/fileformats/um/optimal_array_structuring/test_optimal_array_structure.py b/lib/iris/tests/unit/fileformats/um/optimal_array_structuring/test_optimal_array_structure.py index b153d09638..65316d2736 100644 --- a/lib/iris/tests/unit/fileformats/um/optimal_array_structuring/test_optimal_array_structure.py +++ b/lib/iris/tests/unit/fileformats/um/optimal_array_structuring/test_optimal_array_structure.py @@ -95,7 +95,13 @@ def test_2d(self): ("b", np.array([7, 8, 9, 7, 8, 9])), ] shape, primaries, elems_and_dims = optimal_array_structure(elements) - self.assertEqual(shape, (2, 3,)) + self.assertEqual( + shape, + ( + 2, + 3, + ), + ) self.assertEqual(primaries, set(["a", "b"])) self._check_arrays_and_dims( elems_and_dims, @@ -115,7 +121,13 @@ def test_2d_with_element_values(self): shape, primaries, elems_and_dims = optimal_array_structure( elements, elements_values ) - self.assertEqual(shape, (2, 3,)) + self.assertEqual( + shape, + ( + 2, + 3, + ), + ) self.assertEqual(primaries, set(["a", "b"])) self._check_arrays_and_dims( elems_and_dims, diff --git a/lib/iris/tests/unit/util/test__slice_data_with_keys.py b/lib/iris/tests/unit/util/test__slice_data_with_keys.py index f3bc66f46b..ce2110d347 100644 --- a/lib/iris/tests/unit/util/test__slice_data_with_keys.py +++ b/lib/iris/tests/unit/util/test__slice_data_with_keys.py @@ -105,7 +105,13 @@ def test_1d_all(self): def test_1d_tuple(self): # The call makes tuples into 1-D arrays, and a trailing Ellipsis is # added (for the 1-D case only). - self.check((3,), Index[(2, 0, 1),], [(np.array([2, 0, 1]), Ellipsis)]) + self.check( + (3,), + Index[ + (2, 0, 1), + ], + [(np.array([2, 0, 1]), Ellipsis)], + ) def test_fail_1d_2keys(self): msg = "More slices .* than dimensions" @@ -122,7 +128,9 @@ def test_2d_tuple(self): # trailing Ellipsis is generated. self.check( (3, 2), - Index[(2, 0, 1),], + Index[ + (2, 0, 1), + ], [(slice(None), slice(None)), (np.array([2, 0, 1]), slice(None))], ) @@ -207,12 +215,24 @@ def test_1d_1int_losedim0(self): def test_1d_tuple_nochange(self): # A selection index leaves the dimension intact. - self.check((3,), Index[(1, 0, 1, 2),], expect_map={None: None, 0: 0}) + self.check( + (3,), + Index[ + (1, 0, 1, 2), + ], + expect_map={None: None, 0: 0}, + ) def test_1d_1tuple_nochange(self): # A selection index with only one value in it *still* leaves the # dimension intact. - self.check((3,), Index[(2,),], expect_map={None: None, 0: 0}) + self.check( + (3,), + Index[ + (2,), + ], + expect_map={None: None, 0: 0}, + ) def test_1d_slice_nochange(self): # A slice leaves the dimension intact. @@ -267,7 +287,12 @@ def test_1d_all(self): def test_1d_tuple(self): self.check( - [1, 2, 3], Index[(2, 0, 1, 0),], [3, 1, 2, 1], {None: None, 0: 0} + [1, 2, 3], + Index[ + (2, 0, 1, 0), + ], + [3, 1, 2, 1], + {None: None, 0: 0}, ) def test_fail_1d_2keys(self): @@ -283,7 +308,9 @@ def test_fail_empty_slice(self): def test_2d_tuple(self): self.check( [[11, 12], [21, 22], [31, 32]], - Index[(2, 0, 1),], + Index[ + (2, 0, 1), + ], [[31, 32], [11, 12], [21, 22]], {None: None, 0: 0, 1: 1}, ) diff --git a/requirements/ci/py36.yml b/requirements/ci/py36.yml index bca0d5af2c..74fdfd4b66 100644 --- a/requirements/ci/py36.yml +++ b/requirements/ci/py36.yml @@ -33,7 +33,7 @@ dependencies: # Test dependencies. - asv - - black=19.10b0 + - black=20.8b1 - filelock - imagehash>=4.0 - nose diff --git a/requirements/ci/py37.yml b/requirements/ci/py37.yml index 61fe91b868..a8168db52c 100644 --- a/requirements/ci/py37.yml +++ b/requirements/ci/py37.yml @@ -33,7 +33,7 @@ dependencies: # Test dependencies. - asv - - black=19.10b0 + - black=20.8b1 - filelock - imagehash>=4.0 - nose diff --git a/requirements/test.txt b/requirements/test.txt index 1f3275a781..ff0e388b03 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,7 +1,7 @@ # Test dependencies. asv -black==19.10b0 +black==20.8b1 filelock imagehash>=4.0 nose