@@ -783,13 +783,18 @@ def ds(self):
783783 return self .zarr_group
784784
785785 def open_store_variable (self , name ):
786+ print (f"DEBUG OPEN: Reading variable '{ name } '" )
786787 zarr_array = self .members [name ]
788+ print (
789+ f"DEBUG OPEN: zarr_array.dtype={ zarr_array .dtype } , fill_value={ zarr_array .fill_value } "
790+ )
787791 data = indexing .LazilyIndexedArray (ZarrArrayWrapper (zarr_array ))
788792 try_nczarr = self ._mode == "r"
789793 dimensions , attributes = _get_zarr_dims_and_attrs (
790794 zarr_array , DIMENSION_KEY , try_nczarr
791795 )
792796 attributes = dict (attributes )
797+ print (f"DEBUG OPEN: Original attributes: { attributes } " )
793798
794799 encoding = {
795800 "chunks" : zarr_array .chunks ,
@@ -814,31 +819,60 @@ def open_store_variable(self, name):
814819 }
815820 )
816821
822+ print (
823+ f"DEBUG OPEN: _use_zarr_fill_value_as_mask={ self ._use_zarr_fill_value_as_mask } "
824+ )
825+ print (f"DEBUG OPEN: '_FillValue' in attributes: { '_FillValue' in attributes } " )
826+
817827 if self ._use_zarr_fill_value_as_mask :
818828 # Setting this attribute triggers CF decoding for missing values
819829 # by interpreting Zarr's fill_value to mean the same as netCDF's _FillValue
830+ print (f"DEBUG OPEN: Using zarr fill_value as mask for '{ name } '" )
831+ print ("===========" )
832+ print (f"DEBUG DTYPE: zarr array fill value: { zarr_array .fill_value .dtype } " )
820833 if zarr_array .fill_value is not None :
821834 attributes ["_FillValue" ] = zarr_array .fill_value
835+ print (
836+ f"\t DEBUG OPEN: Set _FillValue to { zarr_array .fill_value } for '{ name } '"
837+ )
838+ print ("===========" )
822839 elif "_FillValue" in attributes :
823840 # TODO update version check for the released version with dtypes
824841 # probably be 3.1
825842 import zarr
826843
827- #
844+ print (f"DEBUG: Processing _FillValue for { name } " )
845+ print (f"DEBUG: Original _FillValue: { attributes ['_FillValue' ]} " )
846+ print (
847+ f"DEBUG: zarr_array.metadata.data_type: { zarr_array .metadata .data_type } "
848+ )
849+
828850 if Version (zarr .__version__ ) >= Version ("3.0.6" ):
851+ native_dtype = zarr_array .metadata .data_type .to_native_dtype ()
852+ print (f"DEBUG: native_dtype: { native_dtype } " )
829853 attributes ["_FillValue" ] = (
830854 # Use the new dtype infrastructure instead of doing xarray
831855 # specific fill value decoding
832856 FillValueCoder .decode (
833857 attributes ["_FillValue" ],
834- zarr_array . metadata . data_type . to_native_dtype () ,
858+ native_dtype ,
835859 )
836860 )
837861 else :
862+ dtype_value = zarr_array .metadata .data_type .value
863+ print (f"DEBUG: dtype_value: { dtype_value } " )
838864 attributes ["_FillValue" ] = FillValueCoder .decode (
839- attributes ["_FillValue" ], zarr_array . metadata . data_type . value
865+ attributes ["_FillValue" ], dtype_value
840866 )
841- return Variable (dimensions , data , attributes , encoding )
867+
868+ print (f"DEBUG: Decoded _FillValue: { attributes ['_FillValue' ]} " )
869+ print (f"DEBUG: Decoded _FillValue type: { type (attributes ['_FillValue' ])} " )
870+
871+ print (f"DEBUG OPEN: Final attributes for '{ name } ': { attributes } " )
872+ variable = Variable (dimensions , data , attributes , encoding )
873+ print (f"DEBUG OPEN: Created variable '{ name } ' with dtype: { variable .dtype } " )
874+
875+ return variable
842876
843877 def get_variables (self ):
844878 return FrozenDict ((k , self .open_store_variable (k )) for k in self .array_keys ())
@@ -953,22 +987,36 @@ def store(
953987 variables_encoded , attributes = self .encode (
954988 {vn : variables [vn ] for vn in new_variable_names }, attributes
955989 )
956- print (f" { variables_encoded = } " )
990+ print ("HERE " )
957991
958992 if existing_variable_names :
959993 # We make sure that values to be appended are encoded *exactly*
960994 # as the current values in the store.
961995 # To do so, we decode variables directly to access the proper encoding,
962996 # without going via xarray.Dataset to avoid needing to load
963997 # index variables into memory.
998+ print (
999+ f"DEBUG APPEND: Processing existing variables: { existing_variable_names } "
1000+ )
1001+ store_vars = {
1002+ k : self .open_store_variable (name = k ) for k in existing_variable_names
1003+ }
1004+ print (
1005+ f"DEBUG APPEND: Store vars dtypes: { [(name , var .dtype ) for name , var in store_vars .items ()]} "
1006+ )
1007+
9641008 existing_vars , _ , _ = conventions .decode_cf_variables (
965- variables = {
966- k : self .open_store_variable (name = k ) for k in existing_variable_names
967- },
1009+ variables = store_vars ,
9681010 # attributes = {} since we don't care about parsing the global
9691011 # "coordinates" attribute
9701012 attributes = {},
9711013 )
1014+ print (
1015+ f"DEBUG APPEND: After CF decode dtypes: { [(name , var .dtype ) for name , var in existing_vars .items ()]} "
1016+ )
1017+ print (
1018+ f"DEBUG APPEND: Variables to append dtypes: { [(name , var .dtype ) for name , var in variables_encoded .items () if name in existing_variable_names ]} "
1019+ )
9721020 # Modified variables must use the same encoding as the store.
9731021 vars_with_encoding = {}
9741022 for vn in existing_variable_names :
@@ -1006,7 +1054,6 @@ def store(
10061054 else :
10071055 variables_to_set = variables_encoded
10081056
1009- print (f"{ variables_to_set = } " )
10101057 self .set_variables (
10111058 variables_to_set , check_encoding_set , writer , unlimited_dims = unlimited_dims
10121059 )
@@ -1015,7 +1062,6 @@ def store(
10151062 if _zarr_v3 ():
10161063 kwargs ["zarr_format" ] = self .zarr_group .metadata .zarr_format
10171064 zarr .consolidate_metadata (self .zarr_group .store , ** kwargs )
1018- print ("DONE STORE.STORE" )
10191065
10201066 def sync (self ):
10211067 pass
@@ -1089,8 +1135,6 @@ def _create_new_array(
10891135 if c in encoding :
10901136 encoding ["config" ][c ] = encoding .pop (c )
10911137
1092- print ("create" )
1093- print (dtype )
10941138 zarr_array = self .zarr_group .create (
10951139 name ,
10961140 shape = shape ,
@@ -1229,8 +1273,6 @@ def set_variables(
12291273
12301274 encoding ["overwrite" ] = self ._mode == "w"
12311275
1232- print (dtype )
1233- print (";sdf" )
12341276 zarr_array = self ._create_new_array (
12351277 name = name ,
12361278 dtype = dtype ,
@@ -1239,8 +1281,6 @@ def set_variables(
12391281 encoding = encoding ,
12401282 attrs = encoded_attrs ,
12411283 )
1242- print (zarr_array )
1243- print (type (zarr_array ))
12441284
12451285 writer .add (v .data , zarr_array , region )
12461286
0 commit comments