3
3
from functools import partial
4
4
from typing import Any , Hashable
5
5
6
- import netCDF4
7
6
import numpy as np
8
7
import pandas as pd
9
8
10
9
from ..core import dtypes , duck_array_ops , indexing
11
10
from ..core .pycompat import is_duck_dask_array
12
11
from ..core .variable import Variable
13
12
13
+ NP_TO_NC_TYPE = {
14
+ "S1" : "\x00 " ,
15
+ "i1" : - 127 ,
16
+ "u1" : 255 ,
17
+ "i2" : - 32767 ,
18
+ "u2" : 65535 ,
19
+ "i4" : - 2147483647 ,
20
+ "u4" : 4294967295 ,
21
+ "i8" : - 9223372036854775806 ,
22
+ "u8" : 18446744073709551614 ,
23
+ "f4" : 9.969209968386869e36 ,
24
+ "f8" : 9.969209968386869e36 ,
25
+ }
26
+
14
27
15
28
class SerializationWarning (RuntimeWarning ):
16
29
"""Warnings about encoding/decoding issues in serialization."""
@@ -184,8 +197,14 @@ def decode(self, variable, name=None):
184
197
pop_to (attrs , encoding , attr , name = name )
185
198
for attr in ("missing_value" , "_FillValue" )
186
199
]
200
+ try :
201
+ default_fillvalue = NP_TO_NC_TYPE [np .dtype (variable .dtype ).str [1 :]]
202
+ raw_fill_values .append (default_fillvalue )
203
+ except KeyError :
204
+ warnings .warn (
205
+ f"A default fill value for dtype { variable .dtype } could not be found"
206
+ )
187
207
188
- raw_fill_values .append (netCDF4 .default_fillvals ["f8" ])
189
208
if raw_fill_values :
190
209
encoded_fill_values = {
191
210
fv
@@ -212,7 +231,6 @@ def decode(self, variable, name=None):
212
231
dtype = dtype ,
213
232
)
214
233
data = lazy_elemwise_func (data , transform , dtype )
215
-
216
234
return Variable (dims , data , attrs , encoding )
217
235
218
236
0 commit comments