From c3f38f238cad33ae6984faef7a95d280d23b1956 Mon Sep 17 00:00:00 2001 From: Kirill Kouzoubov Date: Fri, 25 Aug 2023 13:31:05 +1000 Subject: [PATCH] maint: fix pylint warnings Mostly `dict(..) -> {..}` --- odc/geo/_cog.py | 46 +++++++++++++++++++++--------------------- odc/geo/_rgba.py | 2 +- odc/geo/_xr_interop.py | 4 ++-- odc/geo/geom.py | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/odc/geo/_cog.py b/odc/geo/_cog.py index 30dab90e..3004a34e 100644 --- a/odc/geo/_cog.py +++ b/odc/geo/_cog.py @@ -64,15 +64,15 @@ def _default_cog_opts( *, blocksize: int = 512, shape: SomeShape = (0, 0), is_float: bool = False, **other ) -> Dict[str, Any]: nx, ny = shape_(shape).xy - return dict( - tiled=True, - blockxsize=_adjust_blocksize(blocksize, nx), - blockysize=_adjust_blocksize(blocksize, ny), - zlevel=6, - predictor=3 if is_float else 2, - compress="DEFLATE", + return { + "tiled": True, + "blockxsize": _adjust_blocksize(blocksize, nx), + "blockysize": _adjust_blocksize(blocksize, ny), + "zlevel": 6, + "predictor": 3 if is_float else 2, + "compress": "DEFLATE", **other, - ) + } def _norm_compression_opts( @@ -145,17 +145,17 @@ def _write_cog( if (blocksize % 16) != 0: warnings.warn("Block size must be a multiple of 16, will be adjusted") - rio_opts = dict( - width=w, - height=h, - count=nbands, - dtype=pix.dtype.name, - crs=str(geobox.crs), - transform=geobox.transform, + rio_opts = { + "width": w, + "height": h, + "count": nbands, + "dtype": pix.dtype.name, + "crs": str(geobox.crs), + "transform": geobox.transform, **_default_cog_opts( blocksize=blocksize, shape=wh_(w, h), is_float=pix.dtype.kind == "f" ), - ) + } if nodata is not None: rio_opts.update(nodata=nodata) @@ -376,7 +376,7 @@ def _memfiles_ovr(nlevels) -> Generator[Tuple[rasterio.MemoryFile, ...], None, N for mem in mems[::-1]: if not mem.closed: mem.close() - del mem + del mems def write_cog_layers( @@ -418,13 +418,13 @@ def write_cog_layers( ) rio_opts.update(extra_rio_opts) - first_pass_cfg: Dict[str, Any] = dict( - num_threads="ALL_CPUS", - blocksize=blocksize, - nodata=rio_opts.get("nodata", None), - use_windowed_writes=use_windowed_writes, + first_pass_cfg: Dict[str, Any] = { + "num_threads": "ALL_CPUS", + "blocksize": blocksize, + "nodata": rio_opts.get("nodata", None), + "use_windowed_writes": use_windowed_writes, **_norm_compression_opts(intermediate_compression), - ) + } with _memfiles_ovr(len(xx)) as mm: temp_fname = mm[0].name diff --git a/odc/geo/_rgba.py b/odc/geo/_rgba.py index 357d8541..8fa4f560 100644 --- a/odc/geo/_rgba.py +++ b/odc/geo/_rgba.py @@ -261,7 +261,7 @@ def colorize( nc, cmap_dtype = 4, "uint8" if attrs is None: - attrs = dict(**x.attrs) + attrs = {**x.attrs} attrs.pop("nodata", None) dims = (*x.dims, "band") diff --git a/odc/geo/_xr_interop.py b/odc/geo/_xr_interop.py index 8298e532..ab4ea4eb 100644 --- a/odc/geo/_xr_interop.py +++ b/odc/geo/_xr_interop.py @@ -204,7 +204,7 @@ def _coord_to_xr(name: str, c: Coordinate, **attrs) -> xarray.DataArray: This can then be used to define coordinates for ``xr.Dataset|xr.DataArray`` """ - attrs = dict(units=c.units, resolution=c.resolution, **attrs) + attrs = {"units": c.units, "resolution": c.resolution, **attrs} return xarray.DataArray( c.values, coords={name: c.values}, dims=(name,), attrs=attrs ) @@ -826,7 +826,7 @@ def wrap_xr( ) if nodata is not None: - attrs = dict(nodata=nodata, **attrs) + attrs = {"nodata": nodata, **attrs} out = xarray.DataArray(im, coords=coords, dims=dims, attrs=attrs) if crs_coord_name is not None: diff --git a/odc/geo/geom.py b/odc/geo/geom.py index 5fe0a70d..f6691415 100644 --- a/odc/geo/geom.py +++ b/odc/geo/geom.py @@ -764,7 +764,7 @@ def geojson( if simplify > 0: gg = gg.simplify(simplify) if properties is None: - properties = dict(**props) + properties = {**props} return {"type": "Feature", "geometry": gg.json, "properties": properties} def split(self, splitter: "Geometry") -> Iterable["Geometry"]: