From 9008ea57e1fab5cee91bf706ac4756d8ab0b06fb Mon Sep 17 00:00:00 2001 From: Bill Little Date: Thu, 17 Sep 2020 13:29:29 +0100 Subject: [PATCH 1/2] update black version --- .flake8 | 2 ++ .pre-commit-config.yaml | 2 +- .../general/plot_custom_file_loading.py | 4 ++- lib/iris/_concatenate.py | 2 +- lib/iris/analysis/_area_weighted.py | 6 ++-- lib/iris/analysis/_regrid.py | 12 ++++--- lib/iris/analysis/calculus.py | 12 ++++--- lib/iris/common/mixin.py | 1 - lib/iris/common/resolve.py | 6 ++-- lib/iris/cube.py | 8 ++--- lib/iris/fileformats/_ff.py | 32 +++++++++---------- lib/iris/fileformats/cf.py | 2 +- lib/iris/fileformats/name_loaders.py | 2 +- lib/iris/fileformats/netcdf.py | 2 +- lib/iris/fileformats/nimrod_load_rules.py | 6 ++-- lib/iris/fileformats/pp.py | 12 +++---- lib/iris/plot.py | 2 +- lib/iris/tests/test_cdm.py | 4 +-- lib/iris/tests/test_merge.py | 4 +-- lib/iris/tests/test_netcdf.py | 10 +++--- lib/iris/tests/test_nimrod.py | 4 +-- lib/iris/tests/test_pp_cf.py | 4 +-- .../test_AreaWeightedRegridder.py | 6 ++-- .../unit/common/lenient/test__Lenient.py | 2 +- .../test_AncillaryVariableMetadata.py | 8 ++--- .../unit/common/metadata/test_BaseMetadata.py | 8 +++-- .../metadata/test_CellMeasureMetadata.py | 8 ++--- .../common/metadata/test_CoordMetadata.py | 8 ++--- .../unit/common/metadata/test_CubeMetadata.py | 8 ++--- .../common/mixin/test_LimitedAttributeDict.py | 4 +-- .../unit/coords/test_AncillaryVariable.py | 12 ++----- lib/iris/tests/unit/cube/test_Cube.py | 6 ++-- .../nimrod_load_rules/test_units.py | 12 +++---- .../tests/unit/fileformats/pp/test_PPField.py | 2 +- .../tests/unit/fileformats/pp/test_save.py | 4 +-- .../test_BasicFieldCollation.py | 2 +- .../test_optimal_array_structure.py | 4 +-- .../unit/util/test__slice_data_with_keys.py | 14 ++++---- requirements/ci/py36.yml | 2 +- requirements/ci/py37.yml | 2 +- requirements/test.txt | 2 +- 41 files changed, 129 insertions(+), 124 deletions(-) diff --git a/.flake8 b/.flake8 index 131b6eb1ff..e313fc2ac5 100644 --- a/.flake8 +++ b/.flake8 @@ -4,6 +4,8 @@ # https://flake8.readthedocs.io/en/latest/user/error-codes.html # https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes +max-line-length = 80 +select = C,E,F,W,B,B950 ignore = # E203: whitespace before ':' E203, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2298aa47ca..2c06fc495e 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..9f8d000992 100644 --- a/lib/iris/_concatenate.py +++ b/lib/iris/_concatenate.py @@ -161,7 +161,7 @@ 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/mixin.py b/lib/iris/common/mixin.py index 50ef561036..dc2937af0c 100644 --- a/lib/iris/common/mixin.py +++ b/lib/iris/common/mixin.py @@ -7,7 +7,6 @@ from collections.abc import Mapping from functools import wraps -import re import cf_units 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..3d0854355c 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,7 @@ 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 +3668,7 @@ 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..1b1b2377ff 100644 --- a/lib/iris/fileformats/_ff.py +++ b/lib/iris/fileformats/_ff.py @@ -42,23 +42,23 @@ ("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..5c6e11f3ac 100644 --- a/lib/iris/fileformats/cf.py +++ b/lib/iris/fileformats/cf.py @@ -45,7 +45,7 @@ # 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..ac9a2e35b2 100644 --- a/lib/iris/fileformats/name_loaders.py +++ b/lib/iris/fileformats/name_loaders.py @@ -489,7 +489,7 @@ 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..b83c82c1e7 100644 --- a/lib/iris/fileformats/nimrod_load_rules.py +++ b/lib/iris/fileformats/nimrod_load_rules.py @@ -417,7 +417,7 @@ 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 +456,7 @@ 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 +467,7 @@ 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..406da925b1 100644 --- a/lib/iris/fileformats/pp.py +++ b/lib/iris/fileformats/pp.py @@ -105,10 +105,10 @@ ("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 +163,10 @@ ("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..349f1fea10 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -351,7 +351,7 @@ 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..55e83cdbc6 100644 --- a/lib/iris/tests/test_cdm.py +++ b/lib/iris/tests/test_cdm.py @@ -1135,7 +1135,7 @@ 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 +1459,7 @@ 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..e404216143 100644 --- a/lib/iris/tests/test_merge.py +++ b/lib/iris/tests/test_merge.py @@ -1038,11 +1038,11 @@ 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..75266ff3fe 100644 --- a/lib/iris/tests/test_netcdf.py +++ b/lib/iris/tests/test_netcdf.py @@ -425,25 +425,25 @@ 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),][ + 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. 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..cd392b6e2e 100644 --- a/lib/iris/tests/test_nimrod.py +++ b/lib/iris/tests/test_nimrod.py @@ -73,7 +73,7 @@ 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 +87,7 @@ 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..c818f1b6ac 100644 --- a/lib/iris/tests/test_pp_cf.py +++ b/lib/iris/tests/test_pp_cf.py @@ -87,9 +87,7 @@ def _test_file(self, name): else: fname_name = name - self.assertCML( - cubes, self._ref_dir + ("from_pp", fname_name + ".cml",) - ) + self.assertCML(cubes, self._ref_dir + ("from_pp", fname_name + ".cml")) # 2) Save the Cube and check the netCDF nc_filenames = [] 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..190306f683 100644 --- a/lib/iris/tests/unit/common/lenient/test__Lenient.py +++ b/lib/iris/tests/unit/common/lenient/test__Lenient.py @@ -52,7 +52,7 @@ 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..efc855fae8 100644 --- a/lib/iris/tests/unit/common/metadata/test_AncillaryVariableMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_AncillaryVariableMetadata.py @@ -77,9 +77,7 @@ def setUp(self): self.cls = AncillaryVariableMetadata def test_wraps_docstring(self): - self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, - ) + self.assertEqual(BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__) def test_lenient_service(self): qualname___eq__ = _qualname(self.cls.__eq__) @@ -205,7 +203,7 @@ 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 +322,7 @@ 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..49a12edc75 100644 --- a/lib/iris/tests/unit/common/metadata/test_CellMeasureMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_CellMeasureMetadata.py @@ -82,9 +82,7 @@ def setUp(self): self.cls = CellMeasureMetadata def test_wraps_docstring(self): - self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, - ) + self.assertEqual(BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__) def test_lenient_service(self): qualname___eq__ = _qualname(self.cls.__eq__) @@ -251,7 +249,7 @@ 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 +416,7 @@ 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..cdf7e9fa00 100644 --- a/lib/iris/tests/unit/common/metadata/test_CoordMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_CoordMetadata.py @@ -88,9 +88,7 @@ def setUp(self): self.cls = CoordMetadata def test_wraps_docstring(self): - self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, - ) + self.assertEqual(BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__) def test_lenient_service(self): qualname___eq__ = _qualname(self.cls.__eq__) @@ -270,7 +268,7 @@ 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 +464,7 @@ 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..7ec74968b8 100644 --- a/lib/iris/tests/unit/common/metadata/test_CubeMetadata.py +++ b/lib/iris/tests/unit/common/metadata/test_CubeMetadata.py @@ -106,9 +106,7 @@ def setUp(self): self.cls = CubeMetadata def test_wraps_docstring(self): - self.assertEqual( - BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__, - ) + self.assertEqual(BaseMetadata.__eq__.__doc__, self.cls.__eq__.__doc__) def test_lenient_service(self): qualname___eq__ = _qualname(self.cls.__eq__) @@ -275,7 +273,7 @@ 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 +440,7 @@ 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..a597135ef2 100644 --- a/lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py +++ b/lib/iris/tests/unit/common/mixin/test_LimitedAttributeDict.py @@ -40,12 +40,12 @@ 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..db2f4f070b 100644 --- a/lib/iris/tests/unit/coords/test_AncillaryVariable.py +++ b/lib/iris/tests/unit/coords/test_AncillaryVariable.py @@ -440,9 +440,7 @@ def test_non_time_values(self): "long_name='height of detector', var_name='height', " "attributes={'notes': 'Measured from sea level'})" ) - self.assertEqual( - expected, ancillary_var.__str__(), - ) + self.assertEqual(expected, ancillary_var.__str__()) def test_time_values(self): ancillary_var = AncillaryVariable( @@ -456,9 +454,7 @@ def test_time_values(self): "standard_name=None, calendar='gregorian', " "long_name='time of previous valid detection')" ) - self.assertEqual( - expected, ancillary_var.__str__(), - ) + self.assertEqual(expected, ancillary_var.__str__()) class Test__repr__(tests.IrisTest): @@ -477,9 +473,7 @@ def test_non_time_values(self): "long_name='height of detector', var_name='height', " "attributes={'notes': 'Measured from sea level'})" ) - self.assertEqual( - expected, ancillary_var.__repr__(), - ) + self.assertEqual(expected, ancillary_var.__repr__()) def test_time_values(self): ancillary_var = AncillaryVariable( diff --git a/lib/iris/tests/unit/cube/test_Cube.py b/lib/iris/tests/unit/cube/test_Cube.py index 3b98be6454..01dfe365b4 100644 --- a/lib/iris/tests/unit/cube/test_Cube.py +++ b/lib/iris/tests/unit/cube/test_Cube.py @@ -2004,7 +2004,7 @@ 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 +2155,7 @@ 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 +2257,7 @@ 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..030404d2a4 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 @@ -35,9 +35,7 @@ def setUp(self): ) self.cube = Cube(np.ones((3, 3), dtype=np.float32)) - def _call_units( - self, data=None, units_str=None, - ): + def _call_units(self, data=None, units_str=None): if data is not None: self.cube.data = data if units_str: @@ -106,7 +104,7 @@ 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 +115,7 @@ 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 +125,7 @@ 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 +135,7 @@ 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..7c3ef33182 100644 --- a/lib/iris/tests/unit/fileformats/pp/test_PPField.py +++ b/lib/iris/tests/unit/fileformats/pp/test_PPField.py @@ -35,7 +35,7 @@ ("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..66f6246a0e 100644 --- a/lib/iris/tests/unit/fileformats/pp/test_save.py +++ b/lib/iris/tests/unit/fileformats/pp/test_save.py @@ -324,10 +324,10 @@ 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..0117875093 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,7 @@ 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..d8cd49241b 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,7 @@ 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 +115,7 @@ 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..135bf4a06c 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,9 @@ 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 +124,7 @@ 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 +209,12 @@ 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 +269,7 @@ 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 +285,7 @@ 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 From 5fd76b41bac6d4585d0ca288996d1b8b0be93664 Mon Sep 17 00:00:00 2001 From: Bill Little Date: Thu, 17 Sep 2020 14:53:01 +0100 Subject: [PATCH 2/2] add whatsnew entry --- docs/iris/src/whatsnew/latest.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/iris/src/whatsnew/latest.rst b/docs/iris/src/whatsnew/latest.rst index 04c3caec63..5b29ad62c2 100644 --- a/docs/iris/src/whatsnew/latest.rst +++ b/docs/iris/src/whatsnew/latest.rst @@ -260,6 +260,9 @@ This document explains the changes made to Iris for this release `matplotlib.rcdefaults `_, instead the tests will **always** use ``agg``. (:pull:`3846`) +* `@bjlittle`_ migrated the `black`_ support from ``19.10b0`` to ``20.8b1``. + (:pull:`3866`) + .. _Read the Docs: https://scitools-iris.readthedocs.io/en/latest/ .. _Matplotlib: https://matplotlib.org/