MCPcopy Index your code
hub / github.com/pydata/xarray / NetCDF4ArrayWrapper

Class NetCDF4ArrayWrapper

xarray/backends/netCDF4_.py:104–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103
104class NetCDF4ArrayWrapper(BaseNetCDF4Array):
105 __slots__ = ()
106
107 def get_array(self, needs_lock=True):
108 ds = self.datastore._acquire(needs_lock)
109 variable = ds.variables[self.variable_name]
110 variable.set_auto_maskandscale(False)
111 # only added in netCDF4-python v1.2.8
112 with suppress(AttributeError):
113 variable.set_auto_chartostring(False)
114 return variable
115
116 def __getitem__(self, key):
117 return indexing.explicit_indexing_adapter(
118 key, self.shape, indexing.IndexingSupport.OUTER, self._getitem
119 )
120
121 def _getitem(self, key):
122 if self.datastore.is_remote: # pragma: no cover
123 getitem = functools.partial(robust_getitem, catch=RuntimeError)
124 else:
125 getitem = operator.getitem
126
127 try:
128 with self.datastore.lock:
129 original_array = self.get_array(needs_lock=False)
130 array = getitem(original_array, key)
131 except IndexError as err:
132 # Catch IndexError in netCDF4 and return a more informative
133 # error message. This is most often called when an unsorted
134 # indexer is used before the data is loaded from disk.
135 msg = (
136 "The indexing operation you are attempting to perform "
137 "is not valid on netCDF4.Variable object. Try loading "
138 "your data into memory first by calling .load()."
139 )
140 raise IndexError(msg) from err
141 return array
142
143
144def _encode_nc4_variable(var, name=None):

Callers 2

open_store_variableMethod · 0.85
prepare_variableMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…