Hello,
I’m trying to save a trace after a six hour model run. I see in the Arviz documentation to use `az.to_netcdf’ but when I try to use that I get the following error.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_3891/3643003175.py in <module>
----> 1 az.to_netcdf(trace, filename='prophet_trace')
/opt/conda/lib/python3.7/site-packages/arviz/data/io_netcdf.py in to_netcdf(data, filename, group, coords, dims)
59 """
60 inference_data = convert_to_inference_data(data, group=group, coords=coords, dims=dims)
---> 61 file_name = inference_data.to_netcdf(filename)
62 return file_name
/opt/conda/lib/python3.7/site-packages/arviz/data/inference_data.py in to_netcdf(self, filename, compress, groups)
425 if compress:
426 kwargs["encoding"] = {var_name: {"zlib": True} for var_name in data.variables}
--> 427 data.to_netcdf(filename, mode=mode, group=group, **kwargs)
428 data.close()
429 mode = "a"
/opt/conda/lib/python3.7/site-packages/xarray/core/dataset.py in to_netcdf(self, path, mode, format, group, engine, encoding, unlimited_dims, compute, invalid_netcdf)
1910 unlimited_dims=unlimited_dims,
1911 compute=compute,
-> 1912 invalid_netcdf=invalid_netcdf,
1913 )
1914
/opt/conda/lib/python3.7/site-packages/xarray/backends/api.py in to_netcdf(dataset, path_or_file, mode, format, group, engine, encoding, unlimited_dims, compute, multifile, invalid_netcdf)
1071 # to be parallelized with dask
1072 dump_to_store(
-> 1073 dataset, store, writer, encoding=encoding, unlimited_dims=unlimited_dims
1074 )
1075 if autoclose:
/opt/conda/lib/python3.7/site-packages/xarray/backends/api.py in dump_to_store(dataset, store, writer, encoder, encoding, unlimited_dims)
1117 variables, attrs = encoder(variables, attrs)
1118
-> 1119 store.store(variables, attrs, check_encoding, writer, unlimited_dims=unlimited_dims)
1120
1121
/opt/conda/lib/python3.7/site-packages/xarray/backends/common.py in store(self, variables, attributes, check_encoding_set, writer, unlimited_dims)
259 writer = ArrayWriter()
260
--> 261 variables, attributes = self.encode(variables, attributes)
262
263 self.set_attributes(attributes)
/opt/conda/lib/python3.7/site-packages/xarray/backends/common.py in encode(self, variables, attributes)
348 # All NetCDF files get CF encoded by default, without this attempting
349 # to write times, for example, would fail.
--> 350 variables, attributes = cf_encoder(variables, attributes)
351 variables = {k: self.encode_variable(v) for k, v in variables.items()}
352 attributes = {k: self.encode_attribute(v) for k, v in attributes.items()}
/opt/conda/lib/python3.7/site-packages/xarray/conventions.py in cf_encoder(variables, attributes)
853 _update_bounds_encoding(variables)
854
--> 855 new_vars = {k: encode_cf_variable(v, name=k) for k, v in variables.items()}
856
857 # Remove attrs from bounds variables (issue #2921)
/opt/conda/lib/python3.7/site-packages/xarray/conventions.py in <dictcomp>(.0)
853 _update_bounds_encoding(variables)
854
--> 855 new_vars = {k: encode_cf_variable(v, name=k) for k, v in variables.items()}
856
857 # Remove attrs from bounds variables (issue #2921)
/opt/conda/lib/python3.7/site-packages/xarray/conventions.py in encode_cf_variable(var, needs_copy, name)
273 var = maybe_default_fill_value(var)
274 var = maybe_encode_bools(var)
--> 275 var = ensure_dtype_not_object(var, name=name)
276
277 for attr_name in CF_RELATED_DATA:
/opt/conda/lib/python3.7/site-packages/xarray/conventions.py in ensure_dtype_not_object(var, name)
231 data[missing] = fill_value
232 else:
--> 233 data = _copy_with_dtype(data, dtype=_infer_dtype(data, name))
234
235 assert data.dtype.kind != "O" or data.dtype.metadata
/opt/conda/lib/python3.7/site-packages/xarray/conventions.py in _infer_dtype(array, name)
167 raise ValueError(
168 "unable to infer dtype on variable {!r}; xarray "
--> 169 "cannot serialize arbitrary Python objects".format(name)
170 )
171
ValueError: unable to infer dtype on variable 'changepoints'; xarray cannot serialize arbitrary Python objects
The changepoints are a part of the dims so I’m not sure why it can’t be serialized. Has anyone had any luck saving a trace?