35
35
36
36
37
37
class PydapArrayWrapper (BackendArray ):
38
- def __init__ (self , array , batch = False , cache = None , checksums = True ):
38
+ def __init__ (self , array , batch = False , checksums = True ):
39
39
self .array = array
40
40
self ._batch = batch
41
- self ._cache = cache
42
41
self ._checksums = checksums
43
42
44
43
@property
@@ -55,10 +54,7 @@ def __getitem__(self, key):
55
54
)
56
55
57
56
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?
62
58
# this are both True only for pydap>3.5.5
63
59
from pydap .lib import resolve_batch_for_all_variables
64
60
@@ -69,10 +65,10 @@ def _getitem(self, key):
69
65
)
70
66
else :
71
67
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)
76
72
axis = tuple (n for n , k in enumerate (key ) if isinstance (k , integer_types ))
77
73
if result .ndim + len (axis ) != self .array .ndim and axis :
78
74
result = np .squeeze (result , axis )
@@ -117,8 +113,6 @@ def __init__(
117
113
self .dataset = dataset
118
114
self .group = group
119
115
self ._batch = batch
120
- self ._batch_done = False
121
- self ._array_cache = {} # holds 1D dimension data
122
116
self ._protocol = protocol
123
117
self ._checksums = checksums # true by default
124
118
@@ -201,7 +195,7 @@ def open_store_variable(self, var):
201
195
else :
202
196
# all non-dimension variables
203
197
data = indexing .LazilyIndexedArray (
204
- PydapArrayWrapper (var , self ._batch , self ._array_cache , self . _checksums )
198
+ PydapArrayWrapper (var , self ._batch , self ._checksums )
205
199
)
206
200
207
201
return Variable (dimensions , data , var .attributes )
@@ -248,19 +242,14 @@ def ds(self):
248
242
return get_group (self .dataset , self .group )
249
243
250
244
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"""
254
246
from pydap .lib import get_batch_data
255
247
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
264
253
265
254
266
255
class PydapBackendEntrypoint (BackendEntrypoint ):
0 commit comments