Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var_array_info_path = os.path.join(var_path, '.zarray')
with open(var_array_info_path, 'r') as fp:
var_array_info = json.load(fp)
if var_array_info.get('shape') == var_array_info.get('chunks'):
continue
# Open array and remove chunks from the data
var_array = zarr.convenience.open_array(var_path, 'r+')
if var_array.shape != var_array.chunks:
# TODO (forman): Fully loading data is inefficient and dangerous for large arrays.
# Instead save unchunked to temp and replace existing chunked array dir with temp.
# Fully load data and attrs so we no longer depend on files
data = np.array(var_array)
attributes = var_array.attrs.asdict()
# Save array data
zarr.convenience.save_array(var_path, data, chunks=False, fill_value=var_array.fill_value)
# zarr.convenience.save_array() does not seem save user attributes (file ".zattrs" not written),
# therefore we must modify attrs explicitly:
var_array = zarr.convenience.open_array(var_path, 'r+')
var_array.attrs.update(attributes)