Skip to content

Commit ab53970

Browse files
author
Abel Aoun
committed
Clean
Remove attempts to workaround the fill_value issues.
1 parent 4da8938 commit ab53970

File tree

1 file changed

+0
-61
lines changed

1 file changed

+0
-61
lines changed

xarray/backends/netCDF4_.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
# string used by netCDF4.
5050
_endian_lookup = {"=": "native", ">": "big", "<": "little", "|": "native"}
5151

52-
# according to https://github.com/DennisHeimbigner/netcdf-c/blob/ef94285ac13b011613bb5e905d49b63d2a3bb076/libsrc4/nc4type.c#L486
53-
DEFAULT_HDF_ENUM_FILL_VALUE = 0
54-
DEFAULT_UNDEFINED_ENUM_MEANING = "_UNDEFINED"
5552
NETCDF4_PYTHON_LOCK = combine_locks([NETCDFC_LOCK, HDF5_LOCK])
5653

5754

@@ -126,31 +123,6 @@ def _getitem(self, key):
126123
return array
127124

128125

129-
def replace_mask(self, mask, replacing_value):
130-
ds = self.datastore._acquire(needs_lock=True)
131-
variable = ds.variables[self.variable_name]
132-
variable[mask] = replacing_value
133-
134-
135-
136-
class NetCDF4EnumedArrayWrapper(NetCDF4ArrayWrapper):
137-
__slots__ = ()
138-
139-
def get_array(self, needs_lock=True):
140-
ds = self.datastore._acquire(needs_lock)
141-
variable = ds.variables[self.variable_name]
142-
with suppress(AttributeError):
143-
variable.set_auto_chartostring(False)
144-
return variable
145-
146-
def unmask(self):
147-
ds = self.datastore._acquire(needs_lock=True)
148-
variable = ds.variables[self.variable_name]
149-
variable.set_auto_maskandscale(False)
150-
151-
152-
153-
154126
def _encode_nc4_variable(var):
155127
for coder in [
156128
coding.strings.EncodedStringCoder(allows_unicode=True),
@@ -444,29 +416,8 @@ def open_store_variable(self, name: str, var):
444416
enum_meaning = None
445417
enum_name = None
446418
if isinstance(var.datatype, netCDF4.EnumType):
447-
# Workaround for poorly generated variables:
448-
# When creating a variable typed by an enum
449-
# va_va = self._acquire()[name][:] # get masked array
450-
# old_fill_value = va_va.fill_value
451-
# mask = va_va.mask
452419
enum_meaning = var.datatype.enum_dict
453420
enum_name = var.datatype.name
454-
# Add a meaning to fill_value value if missing
455-
# fill_value = list(var.datatype.enum_dict.values())[0]
456-
# fill_value = attributes.get("_FillValue", DEFAULT_HDF_ENUM_FILL_VALUE)
457-
# attributes["_FillValue"] = fill_value
458-
# masked_data = indexing.LazilyIndexedArray(NetCDF4EnumedArrayWrapper(name, self))
459-
# masked_data.array.replace_mask(fill_value)
460-
# masked_data.array.unmask()
461-
# va_va[mask] = fill_value
462-
# filtered_reversed_enum_meaning = {
463-
# v: k
464-
# for k, v in enum_meaning.items()
465-
# if v == fill_value
466-
# }
467-
# # TODO: manage fill_value, see todo comment taged with [enum][missing_value] below
468-
# if filtered_reversed_enum_meaning.get(fill_value) is None:
469-
# enum_meaning[DEFAULT_UNDEFINED_ENUM_MEANING] = fill_value
470421
attributes["enum_name"] = enum_name
471422
attributes["enum_meaning"] = enum_meaning
472423
data = indexing.LazilyIndexedArray(NetCDF4ArrayWrapper(name, self))
@@ -575,18 +526,6 @@ def prepare_variable(
575526
del attrs["enum_name"]
576527
del attrs["enum_meaning"]
577528
fill_value = None
578-
# TODO [enum][missing_value]:
579-
# What should we do with fill+value on enum ?
580-
# On one hand it makes sens to ensure fill_value is a valid enum
581-
# value.
582-
# On the other hand, HDF and netCDF4 does not enforce this.
583-
# In fact with the current netcdf4 we can end up with variables that
584-
# can be created but not read by ncdump if we set fill_value to a
585-
# value outside the enum range but we can also have clunky files
586-
# with fill_value set to None, that are readable even though
587-
# the default fill_value is outside the enum range too.
588-
# Also, HDF considers the value associated with 0 to be the missing
589-
# value *verify this claim).
590529
if name in self.ds.variables:
591530
nc4_var = self.ds.variables[name]
592531
else:

0 commit comments

Comments
 (0)