38
38
import pandas as pd
39
39
40
40
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
+ )
42
45
from xarray .core import (
43
46
alignment ,
44
47
duck_array_ops ,
126
129
broadcast_variables ,
127
130
calculate_dimensions ,
128
131
)
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
+ )
130
136
from xarray .namedarray .pycompat import array_type , is_chunked_array
131
137
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
+ )
133
142
134
143
if TYPE_CHECKING :
135
144
from dask .dataframe import DataFrame as DaskDataFrame
140
149
from xarray .backends .api import T_NetcdfEngine , T_NetcdfTypes
141
150
from xarray .core .dataarray import DataArray
142
151
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
+ )
144
157
from xarray .core .resample import DatasetResample
145
158
from xarray .core .rolling import DatasetCoarsen , DatasetRolling
146
159
from xarray .core .types import (
@@ -253,7 +266,10 @@ def _get_chunk(var: Variable, chunks, chunkmanager: ChunkManagerEntrypoint):
253
266
)
254
267
255
268
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 ,
257
273
)
258
274
259
275
# Warn where requested chunks break preferred chunks, provided that the variable
@@ -887,7 +903,12 @@ def __dask_tokenize__(self) -> object:
887
903
from dask .base import normalize_token
888
904
889
905
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
+ )
891
912
)
892
913
893
914
def __dask_graph__ (self ):
@@ -1260,7 +1281,9 @@ def _overwrite_indexes(
1260
1281
new_coord_names .remove (name )
1261
1282
1262
1283
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 ,
1264
1287
)
1265
1288
1266
1289
if rename_dims :
@@ -2823,7 +2846,9 @@ def _resolve_frequency(
2823
2846
return self ._replace (variables )
2824
2847
2825
2848
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" ,
2827
2852
) -> Iterator [tuple [Hashable , int | slice | np .ndarray | Variable ]]:
2828
2853
"""Here we make sure
2829
2854
+ indexer has a valid keys
@@ -4105,7 +4130,10 @@ def _validate_interp_indexer(x, new_x):
4105
4130
# GH4739
4106
4131
if obj .__dask_graph__ ():
4107
4132
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
+ )
4109
4137
for k , (index , dest ) in validated_indexers .items ()
4110
4138
}
4111
4139
@@ -4319,7 +4347,9 @@ def _rename_dims(self, name_dict: Mapping[Any, Hashable]) -> dict[Hashable, int]
4319
4347
return {name_dict .get (k , k ): v for k , v in self .sizes .items ()}
4320
4348
4321
4349
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 ],
4323
4353
) -> tuple [dict [Hashable , Index ], dict [Hashable , Variable ]]:
4324
4354
if not self ._indexes :
4325
4355
return {}, {}
@@ -4342,7 +4372,9 @@ def _rename_indexes(
4342
4372
return indexes , variables
4343
4373
4344
4374
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 ],
4346
4378
) -> tuple [
4347
4379
dict [Hashable , Variable ],
4348
4380
set [Hashable ],
@@ -7389,7 +7421,8 @@ def _to_dataframe(self, ordered_dims: Mapping[Any, int]):
7389
7421
]
7390
7422
index = self .coords .to_index ([* ordered_dims ])
7391
7423
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 ,
7393
7426
)
7394
7427
for extension_array_column in extension_array_columns :
7395
7428
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
7436
7469
return self ._to_dataframe (ordered_dims = ordered_dims )
7437
7470
7438
7471
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 ,
7440
7476
) -> None :
7441
7477
from sparse import COO
7442
7478
@@ -7468,7 +7504,10 @@ def _set_sparse_data_from_dataframe(
7468
7504
self [name ] = (dims , data )
7469
7505
7470
7506
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 ,
7472
7511
) -> None :
7473
7512
if not isinstance (idx , pd .MultiIndex ):
7474
7513
for name , values in arrays :
@@ -7591,7 +7630,9 @@ def from_dataframe(cls, dataframe: pd.DataFrame, sparse: bool = False) -> Self:
7591
7630
return obj [dataframe .columns ] if len (dataframe .columns ) else obj
7592
7631
7593
7632
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 ,
7595
7636
) -> DaskDataFrame :
7596
7637
"""
7597
7638
Convert this dataset into a dask.dataframe.DataFrame.
@@ -7675,7 +7716,9 @@ def to_dask_dataframe(
7675
7716
return df
7676
7717
7677
7718
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 ,
7679
7722
) -> dict [str , Any ]:
7680
7723
"""
7681
7724
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):
7908
7951
7909
7952
if isinstance (other , Dataset ):
7910
7953
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 ,
7912
7958
)
7913
7959
else :
7914
7960
other_variable = getattr (other , "variable" , other )
0 commit comments