You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何DataArray.to_zarr()转NetCDF为Zarr失败?疑版本兼容问题

xarray转zarr报错:TypeError: Group.create_array() got an unexpected keyword argument 'exists_ok'

环境信息

  • xarray版本:2024.11.0
  • zarr版本:3.0.7

执行代码

print(xr.__version__, '     ', zarr.__version__)
xr.open_dataarray(r'D:\AVISO_SLA_copernicusmarine\SLA_2001.nc'
                  ).to_zarr(r'D:\AVISO_SLA_copernicusmarine\SLA_2001111.zarr', mode='w')

完整报错栈

TypeError                                 Traceback (most recent call last)
Cell In[22], line 3
      1 print(xr.__version__, '     ', zarr.__version__)
      2 xr.open_dataarray(r'D:\AVISO_SLA_copernicusmarine\SLA_2001.nc'
----> 3                   ).to_zarr(r'D:\AVISO_SLA_copernicusmarine\SLA_2001111.zarr', mode='w')

File c:\Users\Admin\anaconda3\envs\xeofs\Lib\site-packages\xarray\core\dataarray.py:4435, in DataArray.to_zarr(self, store, chunk_store, mode, synchronizer, group, encoding, compute, consolidated, append_dim, region, safe_chunks, storage_options, zarr_version)
   4431 else:
   4432     # No problems with the name - so we're fine!
   4433     dataset = self.to_dataset()
-> 4435 return to_zarr(  # type: ignore[call-overload,misc]
   4436     dataset,
   4437     store=store,
   4438     chunk_store=chunk_store,
   4439     mode=mode,
   4440     synchronizer=synchronizer,
   4441     group=group,
   4442     encoding=encoding,
   4443     compute=compute,
   4444     consolidated=consolidated,
   4445     append_dim=append_dim,
   4446     region=region,
   4447     safe_chunks=safe_chunks,
   4448     storage_options=storage_options,
...
     47     f"{name}={arg}"
     48     for name, arg in zip(kwonly_args[:extra_args], args[-extra_args:], strict=False)
     49 ]

TypeError: Group.create_array() got an unexpected keyword argument 'exists_ok'

问题原因与解决办法

这是明确的版本兼容问题:xarray 2024.11.0在调用zarr的Group.create_array方法时传入了exists_ok参数,但该参数是zarr 3.1.0及以上版本才新增的特性,你当前使用的zarr 3.0.7并不支持这个参数。

可以通过以下两种方式解决:

  1. 升级zarr版本:安装3.1.0或更高版本的zarr
    pip install --upgrade zarr>=3.1.0
    
  2. 降级xarray版本:切换到不依赖该参数的xarray版本(例如2024.9.0)
    pip install xarray==2024.9.0
    

内容的提问来源于stack exchange,提问作者张轻疾

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 04:23:20