Check _FillValue and missing_value if available. Return dictionary with raw fill values and set with encoded fill values. Issue SerializationWarning if appropriate.
(attrs, name, dtype)
| 165 | |
| 166 | |
| 167 | def _check_fill_values(attrs, name, dtype): |
| 168 | """Check _FillValue and missing_value if available. |
| 169 | |
| 170 | Return dictionary with raw fill values and set with encoded fill values. |
| 171 | |
| 172 | Issue SerializationWarning if appropriate. |
| 173 | """ |
| 174 | raw_fill_dict = {} |
| 175 | for attr in ("missing_value", "_FillValue"): |
| 176 | pop_to(attrs, raw_fill_dict, attr, name=name) |
| 177 | encoded_fill_values = set() |
| 178 | for k in list(raw_fill_dict): |
| 179 | v = raw_fill_dict[k] |
| 180 | kfill = {fv for fv in np.ravel(v) if not pd.isnull(fv)} |
| 181 | if not kfill and np.issubdtype(dtype, np.integer): |
| 182 | warnings.warn( |
| 183 | f"variable {name!r} has non-conforming {k!r} " |
| 184 | f"{v!r} defined, dropping {k!r} entirely.", |
| 185 | SerializationWarning, |
| 186 | stacklevel=3, |
| 187 | ) |
| 188 | del raw_fill_dict[k] |
| 189 | else: |
| 190 | encoded_fill_values |= kfill |
| 191 | |
| 192 | if len(encoded_fill_values) > 1: |
| 193 | warnings.warn( |
| 194 | f"variable {name!r} has multiple fill values " |
| 195 | f"{encoded_fill_values} defined, decoding all values to NaN.", |
| 196 | SerializationWarning, |
| 197 | stacklevel=3, |
| 198 | ) |
| 199 | |
| 200 | return raw_fill_dict, encoded_fill_values |
| 201 | |
| 202 | |
| 203 | def _convert_unsigned_fill_value( |