Skip to content

Commit 1def6d0

Browse files
committed
line lengths
1 parent 34fb497 commit 1def6d0

File tree

3 files changed

+91
-25
lines changed

3 files changed

+91
-25
lines changed

xarray/core/dataarray.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@
8484
)
8585
from xarray.plot.accessor import DataArrayPlotAccessor
8686
from xarray.plot.utils import _get_units_from_attrs
87-
from xarray.util.deprecation_helpers import _deprecate_positional_args, deprecate_dims
87+
from xarray.util.deprecation_helpers import (
88+
_deprecate_positional_args,
89+
deprecate_dims,
90+
)
8891

8992
if TYPE_CHECKING:
9093
from dask.dataframe import DataFrame as DaskDataFrame
@@ -3925,7 +3928,9 @@ def to_pandas(self) -> Self | pd.Series | pd.DataFrame:
39253928
return pandas_object
39263929

39273930
def to_dataframe(
3928-
self, name: Hashable | None = None, dim_order: Sequence[Hashable] | None = None
3931+
self,
3932+
name: Hashable | None = None,
3933+
dim_order: Sequence[Hashable] | None = None,
39293934
) -> pd.DataFrame:
39303935
"""Convert this array and its coordinates into a tidy pandas.DataFrame.
39313936
@@ -4193,7 +4198,11 @@ def to_netcdf(
41934198
--------
41944199
Dataset.to_netcdf
41954200
"""
4196-
from xarray.backends.api import DATAARRAY_NAME, DATAARRAY_VARIABLE, to_netcdf
4201+
from xarray.backends.api import (
4202+
DATAARRAY_NAME,
4203+
DATAARRAY_VARIABLE,
4204+
to_netcdf,
4205+
)
41974206

41984207
if self.name is None:
41994208
# If no name is set then use a generic xarray name
@@ -4410,7 +4419,11 @@ def to_zarr(
44104419
:ref:`io.zarr`
44114420
The I/O user guide, with more details and examples.
44124421
"""
4413-
from xarray.backends.api import DATAARRAY_NAME, DATAARRAY_VARIABLE, to_zarr
4422+
from xarray.backends.api import (
4423+
DATAARRAY_NAME,
4424+
DATAARRAY_VARIABLE,
4425+
to_zarr,
4426+
)
44144427

44154428
if self.name is None:
44164429
# If no name is set then use a generic xarray name
@@ -4442,7 +4455,9 @@ def to_zarr(
44424455
)
44434456

44444457
def to_dict(
4445-
self, data: bool | Literal["list", "array"] = "list", encoding: bool = False
4458+
self,
4459+
data: bool | Literal["list", "array"] = "list",
4460+
encoding: bool = False,
44464461
) -> dict[str, Any]:
44474462
"""
44484463
Convert this xarray.DataArray into a dictionary following xarray

xarray/core/dataset.py

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
import pandas as pd
3939

4040
from xarray.coding.calendar_ops import convert_calendar, interp_calendar
41-
from xarray.coding.cftimeindex import CFTimeIndex, _parse_array_of_cftime_strings
41+
from xarray.coding.cftimeindex import (
42+
CFTimeIndex,
43+
_parse_array_of_cftime_strings,
44+
)
4245
from xarray.core import (
4346
alignment,
4447
duck_array_ops,
@@ -126,10 +129,16 @@
126129
broadcast_variables,
127130
calculate_dimensions,
128131
)
129-
from xarray.namedarray.parallelcompat import get_chunked_array_type, guess_chunkmanager
132+
from xarray.namedarray.parallelcompat import (
133+
get_chunked_array_type,
134+
guess_chunkmanager,
135+
)
130136
from xarray.namedarray.pycompat import array_type, is_chunked_array
131137
from xarray.plot.accessor import DatasetPlotAccessor
132-
from xarray.util.deprecation_helpers import _deprecate_positional_args, deprecate_dims
138+
from xarray.util.deprecation_helpers import (
139+
_deprecate_positional_args,
140+
deprecate_dims,
141+
)
133142

134143
if TYPE_CHECKING:
135144
from dask.dataframe import DataFrame as DaskDataFrame
@@ -140,7 +149,11 @@
140149
from xarray.backends.api import T_NetcdfEngine, T_NetcdfTypes
141150
from xarray.core.dataarray import DataArray
142151
from xarray.core.groupby import DatasetGroupBy
143-
from xarray.core.merge import CoercibleMapping, CoercibleValue, _MergeResult
152+
from xarray.core.merge import (
153+
CoercibleMapping,
154+
CoercibleValue,
155+
_MergeResult,
156+
)
144157
from xarray.core.resample import DatasetResample
145158
from xarray.core.rolling import DatasetCoarsen, DatasetRolling
146159
from xarray.core.types import (
@@ -253,7 +266,10 @@ def _get_chunk(var: Variable, chunks, chunkmanager: ChunkManagerEntrypoint):
253266
)
254267

255268
chunk_shape = chunkmanager.normalize_chunks(
256-
chunk_shape, shape=shape, dtype=var.dtype, previous_chunks=preferred_chunk_shape
269+
chunk_shape,
270+
shape=shape,
271+
dtype=var.dtype,
272+
previous_chunks=preferred_chunk_shape,
257273
)
258274

259275
# Warn where requested chunks break preferred chunks, provided that the variable
@@ -887,7 +903,12 @@ def __dask_tokenize__(self) -> object:
887903
from dask.base import normalize_token
888904

889905
return normalize_token(
890-
(type(self), self._variables, self._coord_names, self._attrs or None)
906+
(
907+
type(self),
908+
self._variables,
909+
self._coord_names,
910+
self._attrs or None,
911+
)
891912
)
892913

893914
def __dask_graph__(self):
@@ -1260,7 +1281,9 @@ def _overwrite_indexes(
12601281
new_coord_names.remove(name)
12611282

12621283
replaced = self._replace(
1263-
variables=new_variables, coord_names=new_coord_names, indexes=new_indexes
1284+
variables=new_variables,
1285+
coord_names=new_coord_names,
1286+
indexes=new_indexes,
12641287
)
12651288

12661289
if rename_dims:
@@ -2823,7 +2846,9 @@ def _resolve_frequency(
28232846
return self._replace(variables)
28242847

28252848
def _validate_indexers(
2826-
self, indexers: Mapping[Any, Any], missing_dims: ErrorOptionsWithWarn = "raise"
2849+
self,
2850+
indexers: Mapping[Any, Any],
2851+
missing_dims: ErrorOptionsWithWarn = "raise",
28272852
) -> Iterator[tuple[Hashable, int | slice | np.ndarray | Variable]]:
28282853
"""Here we make sure
28292854
+ indexer has a valid keys
@@ -4105,7 +4130,10 @@ def _validate_interp_indexer(x, new_x):
41054130
# GH4739
41064131
if obj.__dask_graph__():
41074132
dask_indexers = {
4108-
k: (index.to_base_variable().chunk(), dest.to_base_variable().chunk())
4133+
k: (
4134+
index.to_base_variable().chunk(),
4135+
dest.to_base_variable().chunk(),
4136+
)
41094137
for k, (index, dest) in validated_indexers.items()
41104138
}
41114139

@@ -4319,7 +4347,9 @@ def _rename_dims(self, name_dict: Mapping[Any, Hashable]) -> dict[Hashable, int]
43194347
return {name_dict.get(k, k): v for k, v in self.sizes.items()}
43204348

43214349
def _rename_indexes(
4322-
self, name_dict: Mapping[Any, Hashable], dims_dict: Mapping[Any, Hashable]
4350+
self,
4351+
name_dict: Mapping[Any, Hashable],
4352+
dims_dict: Mapping[Any, Hashable],
43234353
) -> tuple[dict[Hashable, Index], dict[Hashable, Variable]]:
43244354
if not self._indexes:
43254355
return {}, {}
@@ -4342,7 +4372,9 @@ def _rename_indexes(
43424372
return indexes, variables
43434373

43444374
def _rename_all(
4345-
self, name_dict: Mapping[Any, Hashable], dims_dict: Mapping[Any, Hashable]
4375+
self,
4376+
name_dict: Mapping[Any, Hashable],
4377+
dims_dict: Mapping[Any, Hashable],
43464378
) -> tuple[
43474379
dict[Hashable, Variable],
43484380
set[Hashable],
@@ -7389,7 +7421,8 @@ def _to_dataframe(self, ordered_dims: Mapping[Any, int]):
73897421
]
73907422
index = self.coords.to_index([*ordered_dims])
73917423
broadcasted_df = pd.DataFrame(
7392-
dict(zip(non_extension_array_columns, data, strict=True)), index=index
7424+
dict(zip(non_extension_array_columns, data, strict=True)),
7425+
index=index,
73937426
)
73947427
for extension_array_column in extension_array_columns:
73957428
extension_array = self.variables[extension_array_column].data.array
@@ -7436,7 +7469,10 @@ def to_dataframe(self, dim_order: Sequence[Hashable] | None = None) -> pd.DataFr
74367469
return self._to_dataframe(ordered_dims=ordered_dims)
74377470

74387471
def _set_sparse_data_from_dataframe(
7439-
self, idx: pd.Index, arrays: list[tuple[Hashable, np.ndarray]], dims: tuple
7472+
self,
7473+
idx: pd.Index,
7474+
arrays: list[tuple[Hashable, np.ndarray]],
7475+
dims: tuple,
74407476
) -> None:
74417477
from sparse import COO
74427478

@@ -7468,7 +7504,10 @@ def _set_sparse_data_from_dataframe(
74687504
self[name] = (dims, data)
74697505

74707506
def _set_numpy_data_from_dataframe(
7471-
self, idx: pd.Index, arrays: list[tuple[Hashable, np.ndarray]], dims: tuple
7507+
self,
7508+
idx: pd.Index,
7509+
arrays: list[tuple[Hashable, np.ndarray]],
7510+
dims: tuple,
74727511
) -> None:
74737512
if not isinstance(idx, pd.MultiIndex):
74747513
for name, values in arrays:
@@ -7591,7 +7630,9 @@ def from_dataframe(cls, dataframe: pd.DataFrame, sparse: bool = False) -> Self:
75917630
return obj[dataframe.columns] if len(dataframe.columns) else obj
75927631

75937632
def to_dask_dataframe(
7594-
self, dim_order: Sequence[Hashable] | None = None, set_index: bool = False
7633+
self,
7634+
dim_order: Sequence[Hashable] | None = None,
7635+
set_index: bool = False,
75957636
) -> DaskDataFrame:
75967637
"""
75977638
Convert this dataset into a dask.dataframe.DataFrame.
@@ -7675,7 +7716,9 @@ def to_dask_dataframe(
76757716
return df
76767717

76777718
def to_dict(
7678-
self, data: bool | Literal["list", "array"] = "list", encoding: bool = False
7719+
self,
7720+
data: bool | Literal["list", "array"] = "list",
7721+
encoding: bool = False,
76797722
) -> dict[str, Any]:
76807723
"""
76817724
Convert this dataset to a dictionary following xarray naming
@@ -7908,7 +7951,10 @@ def apply_over_both(lhs_data_vars, rhs_data_vars, lhs_vars, rhs_vars):
79087951

79097952
if isinstance(other, Dataset):
79107953
new_vars = apply_over_both(
7911-
self.data_vars, other.data_vars, self.variables, other.variables
7954+
self.data_vars,
7955+
other.data_vars,
7956+
self.variables,
7957+
other.variables,
79127958
)
79137959
else:
79147960
other_variable = getattr(other, "variable", other)

xarray/core/missing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ def _apply_over_vars_with_dim(func, self, dim=None, **kwargs):
230230

231231

232232
def get_clean_interp_index(
233-
arr, dim: Hashable, use_coordinate: Hashable | bool = True, strict: bool = True
233+
arr,
234+
dim: Hashable,
235+
use_coordinate: Hashable | bool = True,
236+
strict: bool = True,
234237
):
235238
"""Return index to use for x values in interpolation or curve fitting.
236239
@@ -343,7 +346,8 @@ def interp_na(
343346
if (
344347
dim in self._indexes
345348
and isinstance(
346-
self._indexes[dim].to_pandas_index(), pd.DatetimeIndex | CFTimeIndex
349+
self._indexes[dim].to_pandas_index(),
350+
pd.DatetimeIndex | CFTimeIndex,
347351
)
348352
and use_coordinate
349353
):
@@ -744,7 +748,8 @@ def interp_func(var, x, new_x, method: InterpOptions, kwargs):
744748
new_x0_shape = new_x[0].shape
745749
new_x0_chunks_is_not_none = new_x0_chunks is not None
746750
new_axes = {
747-
ndim + i: new_x0_chunks[i] if new_x0_chunks_is_not_none else new_x0_shape[i]
751+
ndim
752+
+ i: (new_x0_chunks[i] if new_x0_chunks_is_not_none else new_x0_shape[i])
748753
for i in range(new_x[0].ndim)
749754
}
750755

0 commit comments

Comments
 (0)