3535
3636
3737class PydapArrayWrapper (BackendArray ):
38- def __init__ (self , array , batch = False , cache = None , checksums = True ):
38+ def __init__ (self , array , batch = False , checksums = True ):
3939 self .array = array
4040 self ._batch = batch
41- self ._cache = cache
4241 self ._checksums = checksums
4342
4443 @property
@@ -55,10 +54,7 @@ def __getitem__(self, key):
5554 )
5655
5756 def _getitem (self , key ):
58- if self .array .id in self ._cache .keys ():
59- # safely avoid re-downloading some coordinates
60- result = self ._cache [self .array .id ]
61- elif self ._batch and hasattr (self .array , "dataset" ):
57+ if self ._batch and hasattr (self .array , "dataset" ): # is self.array not loaded?
6258 # this are both True only for pydap>3.5.5
6359 from pydap .lib import resolve_batch_for_all_variables
6460
@@ -69,10 +65,10 @@ def _getitem(self, key):
6965 )
7066 else :
7167 result = robust_getitem (self .array , key , catch = ValueError )
72- try :
73- result = np .asarray (result .data )
74- except AttributeError :
75- result = np .asarray (result )
68+ # try:
69+ result = np .asarray (result .data )
70+ # except AttributeError:
71+ # result = np.asarray(result)
7672 axis = tuple (n for n , k in enumerate (key ) if isinstance (k , integer_types ))
7773 if result .ndim + len (axis ) != self .array .ndim and axis :
7874 result = np .squeeze (result , axis )
@@ -117,8 +113,6 @@ def __init__(
117113 self .dataset = dataset
118114 self .group = group
119115 self ._batch = batch
120- self ._batch_done = False
121- self ._array_cache = {} # holds 1D dimension data
122116 self ._protocol = protocol
123117 self ._checksums = checksums # true by default
124118
@@ -201,7 +195,7 @@ def open_store_variable(self, var):
201195 else :
202196 # all non-dimension variables
203197 data = indexing .LazilyIndexedArray (
204- PydapArrayWrapper (var , self ._batch , self ._array_cache , self . _checksums )
198+ PydapArrayWrapper (var , self ._batch , self ._checksums )
205199 )
206200
207201 return Variable (dimensions , data , var .attributes )
@@ -248,19 +242,14 @@ def ds(self):
248242 return get_group (self .dataset , self .group )
249243
250244 def _get_data_array (self , var ):
251- """gets dimension data all at once, storing the numpy
252- arrays within a cached dictionary
253- """
245+ """gets dimension data all at once"""
254246 from pydap .lib import get_batch_data
255247
256- if not self ._batch_done or var .id not in self ._array_cache :
257- # store all dim data into a dict for reuse
258- self ._array_cache = get_batch_data (
259- var .parent , self ._array_cache , self ._checksums
260- )
261- self ._batch_done = True
262-
263- return self ._array_cache [var .id ]
248+ if not var ._is_data_loaded ():
249+ # this implies dat has not been deserialized yet
250+ # runs only once per store/hierarchy
251+ get_batch_data (var .parent , checksums = self ._checksums )
252+ return self .dataset [var .id ].data
264253
265254
266255class PydapBackendEntrypoint (BackendEntrypoint ):
0 commit comments