28
28
from xarray .tests .test_dataset import create_test_data
29
29
30
30
31
- def assert_combined_tile_ids_equal (dict1 , dict2 ) :
31
+ def assert_combined_tile_ids_equal (dict1 : dict , dict2 : dict ) -> None :
32
32
assert len (dict1 ) == len (dict2 )
33
33
for k in dict1 .keys ():
34
34
assert k in dict2 .keys ()
@@ -41,7 +41,9 @@ def test_1d(self):
41
41
input = [ds (0 ), ds (1 )]
42
42
43
43
expected = {(0 ,): ds (0 ), (1 ,): ds (1 )}
44
- actual = _infer_concat_order_from_positions (input )
44
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
45
+ input
46
+ )
45
47
assert_combined_tile_ids_equal (expected , actual )
46
48
47
49
def test_2d (self ):
@@ -56,7 +58,9 @@ def test_2d(self):
56
58
(2 , 0 ): ds (4 ),
57
59
(2 , 1 ): ds (5 ),
58
60
}
59
- actual = _infer_concat_order_from_positions (input )
61
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
62
+ input
63
+ )
60
64
assert_combined_tile_ids_equal (expected , actual )
61
65
62
66
def test_3d (self ):
@@ -80,40 +84,50 @@ def test_3d(self):
80
84
(1 , 2 , 0 ): ds (10 ),
81
85
(1 , 2 , 1 ): ds (11 ),
82
86
}
83
- actual = _infer_concat_order_from_positions (input )
87
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
88
+ input
89
+ )
84
90
assert_combined_tile_ids_equal (expected , actual )
85
91
86
92
def test_single_dataset (self ):
87
93
ds = create_test_data (0 )
88
94
input = [ds ]
89
95
90
96
expected = {(0 ,): ds }
91
- actual = _infer_concat_order_from_positions (input )
97
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
98
+ input
99
+ )
92
100
assert_combined_tile_ids_equal (expected , actual )
93
101
94
102
def test_redundant_nesting (self ):
95
103
ds = create_test_data
96
104
input = [[ds (0 )], [ds (1 )]]
97
105
98
106
expected = {(0 , 0 ): ds (0 ), (1 , 0 ): ds (1 )}
99
- actual = _infer_concat_order_from_positions (input )
107
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
108
+ input
109
+ )
100
110
assert_combined_tile_ids_equal (expected , actual )
101
111
102
112
def test_ignore_empty_list (self ):
103
113
ds = create_test_data (0 )
104
- input = [ds , []]
114
+ input : list = [ds , []]
105
115
expected = {(0 ,): ds }
106
- actual = _infer_concat_order_from_positions (input )
116
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
117
+ input
118
+ )
107
119
assert_combined_tile_ids_equal (expected , actual )
108
120
109
121
def test_uneven_depth_input (self ):
110
122
# Auto_combine won't work on ragged input
111
123
# but this is just to increase test coverage
112
124
ds = create_test_data
113
- input = [ds (0 ), [ds (1 ), ds (2 )]]
125
+ input : list = [ds (0 ), [ds (1 ), ds (2 )]]
114
126
115
127
expected = {(0 ,): ds (0 ), (1 , 0 ): ds (1 ), (1 , 1 ): ds (2 )}
116
- actual = _infer_concat_order_from_positions (input )
128
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
129
+ input
130
+ )
117
131
assert_combined_tile_ids_equal (expected , actual )
118
132
119
133
def test_uneven_length_input (self ):
@@ -123,15 +137,19 @@ def test_uneven_length_input(self):
123
137
input = [[ds (0 )], [ds (1 ), ds (2 )]]
124
138
125
139
expected = {(0 , 0 ): ds (0 ), (1 , 0 ): ds (1 ), (1 , 1 ): ds (2 )}
126
- actual = _infer_concat_order_from_positions (input )
140
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
141
+ input
142
+ )
127
143
assert_combined_tile_ids_equal (expected , actual )
128
144
129
145
def test_infer_from_datasets (self ):
130
146
ds = create_test_data
131
147
input = [ds (0 ), ds (1 )]
132
148
133
149
expected = {(0 ,): ds (0 ), (1 ,): ds (1 )}
134
- actual = _infer_concat_order_from_positions (input )
150
+ actual : dict [tuple [int , ...], Dataset ] = _infer_concat_order_from_positions (
151
+ input
152
+ )
135
153
assert_combined_tile_ids_equal (expected , actual )
136
154
137
155
@@ -581,8 +599,8 @@ def test_auto_combine_2d_combine_attrs_kwarg(self):
581
599
expected_dict ["override" ] = expected .copy (deep = True )
582
600
expected_dict ["override" ].attrs = {"a" : 1 }
583
601
f = lambda attrs , context : attrs [0 ]
584
- expected_dict [f ] = expected .copy (deep = True )
585
- expected_dict [f ].attrs = f ([{"a" : 1 }], None )
602
+ expected_dict [f ] = expected .copy (deep = True ) # type: ignore[index]
603
+ expected_dict [f ].attrs = f ([{"a" : 1 }], None ) # type: ignore[index]
586
604
587
605
datasets = [[ds (0 ), ds (1 ), ds (2 )], [ds (3 ), ds (4 ), ds (5 )]]
588
606
@@ -606,7 +624,7 @@ def test_auto_combine_2d_combine_attrs_kwarg(self):
606
624
datasets ,
607
625
concat_dim = ["dim1" , "dim2" ],
608
626
data_vars = "all" ,
609
- combine_attrs = combine_attrs ,
627
+ combine_attrs = combine_attrs , # type: ignore[arg-type]
610
628
)
611
629
assert_identical (result , expected )
612
630
@@ -632,11 +650,11 @@ def test_invalid_hypercube_input(self):
632
650
):
633
651
combine_nested (datasets , concat_dim = ["dim1" , "dim2" ])
634
652
635
- datasets = [[ds (0 ), ds (1 )], [[ds (3 ), ds (4 )]]]
653
+ datasets2 : list = [[ds (0 ), ds (1 )], [[ds (3 ), ds (4 )]]]
636
654
with pytest .raises (
637
655
ValueError , match = r"sub-lists do not have consistent depths"
638
656
):
639
- combine_nested (datasets , concat_dim = ["dim1" , "dim2" ])
657
+ combine_nested (datasets2 , concat_dim = ["dim1" , "dim2" ])
640
658
641
659
datasets = [[ds (0 ), ds (1 )], [ds (3 ), ds (4 )]]
642
660
with pytest .raises (ValueError , match = r"concat_dims has length" ):
@@ -1019,7 +1037,7 @@ def test_infer_order_from_coords(self):
1019
1037
objs = [data .isel (dim2 = slice (4 , 9 )), data .isel (dim2 = slice (4 ))]
1020
1038
actual = combine_by_coords (objs , data_vars = "all" )
1021
1039
expected = data
1022
- assert expected .broadcast_equals (actual )
1040
+ assert expected .broadcast_equals (actual ) # type: ignore[arg-type]
1023
1041
1024
1042
with set_options (use_new_combine_kwarg_defaults = True ):
1025
1043
actual = combine_by_coords (objs )
@@ -1067,7 +1085,7 @@ def test_combine_by_coords_still_fails(self):
1067
1085
# https://github.com/pydata/xarray/issues/508
1068
1086
datasets = [Dataset ({"x" : 0 }, {"y" : 0 }), Dataset ({"x" : 1 }, {"y" : 1 , "z" : 1 })]
1069
1087
with pytest .raises (ValueError ):
1070
- combine_by_coords (datasets , "y" )
1088
+ combine_by_coords (datasets , "y" ) # type: ignore[arg-type]
1071
1089
1072
1090
def test_combine_by_coords_no_concat (self ):
1073
1091
objs = [Dataset ({"x" : 0 }), Dataset ({"y" : 1 })]
0 commit comments