-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: support for xarray objects #59
Comments
Hi @andersy005, in this case I think the problem is that you need to call the More generally, I haven't tested xarray in provenance/provenance/serializers.py Lines 78 to 88 in d946b58
|
Thank you for getting back to me @bmabey!
👍 I tried registering xarray serializers, but I ran into a import xarray as xr
import provenance as p
ds = xr.tutorial.open_dataset('rasm')
# Register xarray serializers via netCDF
def xr_dataset_netcdf_dump(ds, filename, **kwargs):
return ds.to_netcdf(filename, **kwargs)
def xr_dataset_netcdf_load(filename, **kwargs):
return xr.open_dataset(filename, **kwargs)
p.serializers.register_serializer('xr_dataset', xr_dataset_netcdf_dump, xr_dataset_netcdf_load,
classes=[xr.Dataset])
@p.provenance()
def anomaly(ds, groupby='time.year'):
"""Compute annual annomalies"""
group = ds.groupby(groupby)
clim = group.mean()
return ds - clim
%%time
anom = anomaly(ds.Tair) Stacktrace---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<timed exec> in <module>
<boltons.funcutils.FunctionBuilder-4> in anomaly(ds, groupby)
~/devel/ncar/provenance/provenance/core.py in _provenance_wrapper(*args, **kargs)
274 inputs['filehash'] = value_id
275
--> 276 input_hashes, input_artifact_ids = hash_inputs(inputs, repos.get_check_mutations(), func_info)
277
278 id = create_id(input_hashes, **func_info['identifiers'])
~/devel/ncar/provenance/provenance/core.py in hash_inputs(inputs, check_mutations, func_info)
106
107 for k, v in inputs['kargs'].items():
--> 108 h, artifacts = hash(v, hasher=ah.artifact_hasher())
109 kargs[k] = h
110 for a in artifacts:
~/devel/ncar/provenance/provenance/hashing.py in hash(obj, hasher, hash_name, coerce_mmap)
279 hasher = Hasher(hash_name=hash_name)
280
--> 281 return hasher.hash(obj)
282
283
~/devel/ncar/provenance/provenance/artifact_hasher.py in hash(self, obj)
41
42 def hash(self, obj):
---> 43 return (h.NumpyHasher.hash(self, obj), self.artifacts.values())
44
45
~/devel/ncar/provenance/provenance/hashing.py in hash(self, obj)
79 def hash(self, obj):
80 try:
---> 81 self.dump(obj)
82 except pickle.PicklingError as e:
83 e.args += ('PicklingError while hashing %r: %r' % (obj, e),)
~/opt/miniconda3/envs/sandbox/lib/python3.8/site-packages/cloudpickle/cloudpickle_fast.py in dump(self, obj)
546 def dump(self, obj):
547 try:
--> 548 return Pickler.dump(self, obj)
549 except RuntimeError as e:
550 if "recursion" in e.args[0]:
TypeError: save_global() missing 1 required positional argument: 'obj' |
@andersy005 The serializers that you wrote look good. For context, As a sanity test... can you save your |
First, fantastic work!
provenance
has a lot of features I am looking for 😀.Second, I would like to extend
provenance
functionality to support one of my use cases i.e. tracking provenance ofxarray
objects. Currently, trying provenance on xarray objects results in an error.See this example
I would like to help with this but I want to confirm whether this is something
provenance
devs would be willing to have/support and/or I may be missing something?The text was updated successfully, but these errors were encountered: