From e4496fead2a1505d0d05a21457aed4037b56bd81 Mon Sep 17 00:00:00 2001 From: Mathias Hauser Date: Mon, 8 Jan 2024 17:53:00 +0100 Subject: [PATCH] small string fixes (#8598) --- xarray/coding/cftimeindex.py | 2 +- xarray/core/combine.py | 2 +- xarray/core/computation.py | 6 +++--- xarray/core/dataarray.py | 4 ++-- xarray/core/dataset.py | 8 +++----- xarray/core/formatting_html.py | 4 ++-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/xarray/coding/cftimeindex.py b/xarray/coding/cftimeindex.py index 70e88081545..b38d815187d 100644 --- a/xarray/coding/cftimeindex.py +++ b/xarray/coding/cftimeindex.py @@ -553,7 +553,7 @@ def shift(self, n: int | float, freq: str | timedelta): return self + n * to_offset(freq) else: raise TypeError( - "'freq' must be of type " f"str or datetime.timedelta, got {freq}." + f"'freq' must be of type str or datetime.timedelta, got {freq}." ) def __add__(self, other): diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 1939e2c7d0f..10f194bf9f5 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -179,7 +179,7 @@ def _check_shape_tile_ids(combined_tile_ids): raise ValueError( "The supplied objects do not form a hypercube " "because sub-lists do not have consistent " - "lengths along dimension" + str(dim) + f"lengths along dimension {dim}" ) diff --git a/xarray/core/computation.py b/xarray/core/computation.py index c6c7ef97e42..553836961b0 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -811,7 +811,7 @@ def func(*arrays): pass else: raise ValueError( - "unknown setting for chunked array handling in " f"apply_ufunc: {dask}" + f"unknown setting for chunked array handling in apply_ufunc: {dask}" ) else: if vectorize: @@ -1383,7 +1383,7 @@ def cov( ) if weights is not None: if not isinstance(weights, DataArray): - raise TypeError("Only xr.DataArray is supported." f"Given {type(weights)}.") + raise TypeError(f"Only xr.DataArray is supported. Given {type(weights)}.") return _cov_corr(da_a, da_b, weights=weights, dim=dim, ddof=ddof, method="cov") @@ -1487,7 +1487,7 @@ def corr( ) if weights is not None: if not isinstance(weights, DataArray): - raise TypeError("Only xr.DataArray is supported." f"Given {type(weights)}.") + raise TypeError(f"Only xr.DataArray is supported. Given {type(weights)}.") return _cov_corr(da_a, da_b, weights=weights, dim=dim, method="corr") diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 4bb5498e6a9..e8d6f82136b 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -2296,7 +2296,7 @@ def interp( """ if self.dtype.kind not in "uifc": raise TypeError( - "interp only works for a numeric type array. " f"Given {self.dtype}." + f"interp only works for a numeric type array. Given {self.dtype}." ) ds = self._to_temp_dataset().interp( coords, @@ -2423,7 +2423,7 @@ def interp_like( """ if self.dtype.kind not in "uifc": raise TypeError( - "interp only works for a numeric type array. " f"Given {self.dtype}." + f"interp only works for a numeric type array. Given {self.dtype}." ) ds = self._to_temp_dataset().interp_like( other, method=method, kwargs=kwargs, assume_sorted=assume_sorted diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 869dad96f9e..c19083915f4 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -7159,9 +7159,9 @@ def to_pandas(self) -> pd.Series | pd.DataFrame: if len(self.dims) == 1: return self.to_dataframe() raise ValueError( - "cannot convert Datasets with %s dimensions into " + f"cannot convert Datasets with {len(self.dims)} dimensions into " "pandas objects without changing the number of dimensions. " - "Please use Dataset.to_dataframe() instead." % len(self.dims) + "Please use Dataset.to_dataframe() instead." ) def _to_dataframe(self, ordered_dims: Mapping[Any, int]): @@ -7564,9 +7564,7 @@ def from_dict(cls, d: Mapping[Any, Any]) -> Self: for k, v in variables } except KeyError as e: - raise ValueError( - "cannot convert dict without the key " f"'{str(e.args[0])}'" - ) + raise ValueError(f"cannot convert dict without the key '{str(e.args[0])}'") obj = cls(variable_dict) # what if coords aren't dims? diff --git a/xarray/core/formatting_html.py b/xarray/core/formatting_html.py index efd74111823..2c76b182207 100644 --- a/xarray/core/formatting_html.py +++ b/xarray/core/formatting_html.py @@ -47,7 +47,7 @@ def format_dims(dim_sizes, dims_with_index) -> str: } dims_li = "".join( - f"
  • " f"{escape(str(dim))}: {size}
  • " + f"
  • {escape(str(dim))}: {size}
  • " for dim, size in dim_sizes.items() ) @@ -56,7 +56,7 @@ def format_dims(dim_sizes, dims_with_index) -> str: def summarize_attrs(attrs) -> str: attrs_dl = "".join( - f"
    {escape(str(k))} :
    " f"
    {escape(str(v))}
    " + f"
    {escape(str(k))} :
    {escape(str(v))}
    " for k, v in attrs.items() )