@@ -35,6 +35,10 @@ class Group(MutableMapping):
35
35
chunk_store : MutableMapping, optional
36
36
Separate storage for chunks. If not provided, `store` will be used
37
37
for storage of both chunks and metadata.
38
+ cache_attrs : bool, optional
39
+ If True (default), user attributes will be cached for attribute read
40
+ operations. If False, user attributes are reloaded from the store prior
41
+ to all attribute read operations.
38
42
synchronizer : object, optional
39
43
Array synchronizer.
40
44
@@ -86,7 +90,7 @@ class Group(MutableMapping):
86
90
"""
87
91
88
92
def __init__ (self , store , path = None , read_only = False , chunk_store = None ,
89
- synchronizer = None ):
93
+ cache_attrs = True , synchronizer = None ):
90
94
91
95
self ._store = store
92
96
self ._chunk_store = chunk_store
@@ -115,7 +119,7 @@ def __init__(self, store, path=None, read_only=False, chunk_store=None,
115
119
# setup attributes
116
120
akey = self ._key_prefix + attrs_key
117
121
self ._attrs = Attributes (store , key = akey , read_only = read_only ,
118
- synchronizer = synchronizer )
122
+ cache = cache_attrs , synchronizer = synchronizer )
119
123
120
124
# setup info
121
125
self ._info = InfoReporter (self )
@@ -320,10 +324,12 @@ def __getitem__(self, item):
320
324
path = self ._item_path (item )
321
325
if contains_array (self ._store , path ):
322
326
return Array (self ._store , read_only = self ._read_only , path = path ,
323
- chunk_store = self ._chunk_store , synchronizer = self ._synchronizer )
327
+ chunk_store = self ._chunk_store ,
328
+ synchronizer = self ._synchronizer , cache_attrs = self .attrs .cache )
324
329
elif contains_group (self ._store , path ):
325
330
return Group (self ._store , read_only = self ._read_only , path = path ,
326
- chunk_store = self ._chunk_store , synchronizer = self ._synchronizer )
331
+ chunk_store = self ._chunk_store , cache_attrs = self .attrs .cache ,
332
+ synchronizer = self ._synchronizer )
327
333
else :
328
334
raise KeyError (item )
329
335
@@ -403,6 +409,7 @@ def groups(self):
403
409
if contains_group (self ._store , path ):
404
410
yield key , Group (self ._store , path = path , read_only = self ._read_only ,
405
411
chunk_store = self ._chunk_store ,
412
+ cache_attrs = self .attrs .cache ,
406
413
synchronizer = self ._synchronizer )
407
414
408
415
def array_keys (self ):
@@ -447,6 +454,7 @@ def arrays(self):
447
454
if contains_array (self ._store , path ):
448
455
yield key , Array (self ._store , path = path , read_only = self ._read_only ,
449
456
chunk_store = self ._chunk_store ,
457
+ cache_attrs = self .attrs .cache ,
450
458
synchronizer = self ._synchronizer )
451
459
452
460
def visitvalues (self , func ):
@@ -649,7 +657,8 @@ def _create_group_nosync(self, name, overwrite=False):
649
657
overwrite = overwrite )
650
658
651
659
return Group (self ._store , path = path , read_only = self ._read_only ,
652
- chunk_store = self ._chunk_store , synchronizer = self ._synchronizer )
660
+ chunk_store = self ._chunk_store , cache_attrs = self .attrs .cache ,
661
+ synchronizer = self ._synchronizer )
653
662
654
663
def create_groups (self , * names , ** kwargs ):
655
664
"""Convenience method to create multiple groups in a single call."""
@@ -692,7 +701,8 @@ def _require_group_nosync(self, name, overwrite=False):
692
701
overwrite = overwrite )
693
702
694
703
return Group (self ._store , path = path , read_only = self ._read_only ,
695
- chunk_store = self ._chunk_store , synchronizer = self ._synchronizer )
704
+ chunk_store = self ._chunk_store , cache_attrs = self .attrs .cache ,
705
+ synchronizer = self ._synchronizer )
696
706
697
707
def require_groups (self , * names ):
698
708
"""Convenience method to require multiple groups in a single call."""
@@ -760,6 +770,7 @@ def _create_dataset_nosync(self, name, data=None, **kwargs):
760
770
761
771
# determine synchronizer
762
772
kwargs .setdefault ('synchronizer' , self ._synchronizer )
773
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
763
774
764
775
# create array
765
776
if data is None :
@@ -804,9 +815,10 @@ def _require_dataset_nosync(self, name, shape, dtype=None, exact=False,
804
815
805
816
synchronizer = kwargs .get ('synchronizer' , self ._synchronizer )
806
817
cache_metadata = kwargs .get ('cache_metadata' , True )
818
+ cache_attrs = kwargs .get ('cache_attrs' , self .attrs .cache )
807
819
a = Array (self ._store , path = path , read_only = self ._read_only ,
808
820
chunk_store = self ._chunk_store , synchronizer = synchronizer ,
809
- cache_metadata = cache_metadata )
821
+ cache_metadata = cache_metadata , cache_attrs = cache_attrs )
810
822
shape = normalize_shape (shape )
811
823
if shape != a .shape :
812
824
raise TypeError ('shape do not match existing array; expected {}, got {}'
@@ -834,6 +846,7 @@ def create(self, name, **kwargs):
834
846
def _create_nosync (self , name , ** kwargs ):
835
847
path = self ._item_path (name )
836
848
kwargs .setdefault ('synchronizer' , self ._synchronizer )
849
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
837
850
return create (store = self ._store , path = path , chunk_store = self ._chunk_store ,
838
851
** kwargs )
839
852
@@ -845,6 +858,7 @@ def empty(self, name, **kwargs):
845
858
def _empty_nosync (self , name , ** kwargs ):
846
859
path = self ._item_path (name )
847
860
kwargs .setdefault ('synchronizer' , self ._synchronizer )
861
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
848
862
return empty (store = self ._store , path = path , chunk_store = self ._chunk_store ,
849
863
** kwargs )
850
864
@@ -856,6 +870,7 @@ def zeros(self, name, **kwargs):
856
870
def _zeros_nosync (self , name , ** kwargs ):
857
871
path = self ._item_path (name )
858
872
kwargs .setdefault ('synchronizer' , self ._synchronizer )
873
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
859
874
return zeros (store = self ._store , path = path , chunk_store = self ._chunk_store ,
860
875
** kwargs )
861
876
@@ -867,6 +882,7 @@ def ones(self, name, **kwargs):
867
882
def _ones_nosync (self , name , ** kwargs ):
868
883
path = self ._item_path (name )
869
884
kwargs .setdefault ('synchronizer' , self ._synchronizer )
885
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
870
886
return ones (store = self ._store , path = path , chunk_store = self ._chunk_store , ** kwargs )
871
887
872
888
def full (self , name , fill_value , ** kwargs ):
@@ -877,6 +893,7 @@ def full(self, name, fill_value, **kwargs):
877
893
def _full_nosync (self , name , fill_value , ** kwargs ):
878
894
path = self ._item_path (name )
879
895
kwargs .setdefault ('synchronizer' , self ._synchronizer )
896
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
880
897
return full (store = self ._store , path = path , chunk_store = self ._chunk_store ,
881
898
fill_value = fill_value , ** kwargs )
882
899
@@ -888,6 +905,7 @@ def array(self, name, data, **kwargs):
888
905
def _array_nosync (self , name , data , ** kwargs ):
889
906
path = self ._item_path (name )
890
907
kwargs .setdefault ('synchronizer' , self ._synchronizer )
908
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
891
909
return array (data , store = self ._store , path = path , chunk_store = self ._chunk_store ,
892
910
** kwargs )
893
911
@@ -899,6 +917,7 @@ def empty_like(self, name, data, **kwargs):
899
917
def _empty_like_nosync (self , name , data , ** kwargs ):
900
918
path = self ._item_path (name )
901
919
kwargs .setdefault ('synchronizer' , self ._synchronizer )
920
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
902
921
return empty_like (data , store = self ._store , path = path ,
903
922
chunk_store = self ._chunk_store , ** kwargs )
904
923
@@ -910,6 +929,7 @@ def zeros_like(self, name, data, **kwargs):
910
929
def _zeros_like_nosync (self , name , data , ** kwargs ):
911
930
path = self ._item_path (name )
912
931
kwargs .setdefault ('synchronizer' , self ._synchronizer )
932
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
913
933
return zeros_like (data , store = self ._store , path = path ,
914
934
chunk_store = self ._chunk_store , ** kwargs )
915
935
@@ -921,6 +941,7 @@ def ones_like(self, name, data, **kwargs):
921
941
def _ones_like_nosync (self , name , data , ** kwargs ):
922
942
path = self ._item_path (name )
923
943
kwargs .setdefault ('synchronizer' , self ._synchronizer )
944
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
924
945
return ones_like (data , store = self ._store , path = path ,
925
946
chunk_store = self ._chunk_store , ** kwargs )
926
947
@@ -932,6 +953,7 @@ def full_like(self, name, data, **kwargs):
932
953
def _full_like_nosync (self , name , data , ** kwargs ):
933
954
path = self ._item_path (name )
934
955
kwargs .setdefault ('synchronizer' , self ._synchronizer )
956
+ kwargs .setdefault ('cache_attrs' , self .attrs .cache )
935
957
return full_like (data , store = self ._store , path = path ,
936
958
chunk_store = self ._chunk_store , ** kwargs )
937
959
@@ -971,7 +993,8 @@ def _normalize_store_arg(store, clobber=False):
971
993
return normalize_store_arg (store , clobber = clobber , default = DictStore )
972
994
973
995
974
- def group (store = None , overwrite = False , chunk_store = None , synchronizer = None , path = None ):
996
+ def group (store = None , overwrite = False , chunk_store = None ,
997
+ cache_attrs = True , synchronizer = None , path = None ):
975
998
"""Create a group.
976
999
977
1000
Parameters
@@ -984,6 +1007,10 @@ def group(store=None, overwrite=False, chunk_store=None, synchronizer=None, path
984
1007
chunk_store : MutableMapping, optional
985
1008
Separate storage for chunks. If not provided, `store` will be used
986
1009
for storage of both chunks and metadata.
1010
+ cache_attrs : bool, optional
1011
+ If True (default), user attributes will be cached for attribute read
1012
+ operations. If False, user attributes are reloaded from the store prior
1013
+ to all attribute read operations.
987
1014
synchronizer : object, optional
988
1015
Array synchronizer.
989
1016
path : string, optional
@@ -1021,10 +1048,10 @@ def group(store=None, overwrite=False, chunk_store=None, synchronizer=None, path
1021
1048
path = path )
1022
1049
1023
1050
return Group (store , read_only = False , chunk_store = chunk_store ,
1024
- synchronizer = synchronizer , path = path )
1051
+ cache_attrs = cache_attrs , synchronizer = synchronizer , path = path )
1025
1052
1026
1053
1027
- def open_group (store , mode = 'a' , synchronizer = None , path = None ):
1054
+ def open_group (store , mode = 'a' , cache_attrs = True , synchronizer = None , path = None ):
1028
1055
"""Open a group using file-mode-like semantics.
1029
1056
1030
1057
Parameters
@@ -1036,6 +1063,10 @@ def open_group(store, mode='a', synchronizer=None, path=None):
1036
1063
read/write (must exist); 'a' means read/write (create if doesn't
1037
1064
exist); 'w' means create (overwrite if exists); 'w-' means create
1038
1065
(fail if exists).
1066
+ cache_attrs : bool, optional
1067
+ If True (default), user attributes will be cached for attribute read
1068
+ operations. If False, user attributes are reloaded from the store prior
1069
+ to all attribute read operations.
1039
1070
synchronizer : object, optional
1040
1071
Array synchronizer.
1041
1072
path : string, optional
@@ -1093,4 +1124,5 @@ def open_group(store, mode='a', synchronizer=None, path=None):
1093
1124
# determine read only status
1094
1125
read_only = mode == 'r'
1095
1126
1096
- return Group (store , read_only = read_only , synchronizer = synchronizer , path = path )
1127
+ return Group (store , read_only = read_only , cache_attrs = cache_attrs ,
1128
+ synchronizer = synchronizer , path = path )
0 commit comments