-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Save arbitrary Python objects to netCDF #1415
Comments
I would be OK with this if it required explicitly setting a keyword argument, e.g., |
I would certainly be interested in giving this a try, although I'm not exactly sure what would go where yet. It seems like this might possibly be something that would be more appropriate in the netCDF4-python library - should I start an issue over there? |
Sure, there's no harm in asking. My guess is that this isn't a good fit, but I'm not entirely sure. |
Yeah, looking at it, it's probably not a thing for them. I thought something like: # implement something like
# strs = nc.createVariable('strs', str, ('strs_dim',))
objs = nc.createVariable('objs', object, ('objs_dim',)) But I see that the |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
I am looking to transition from pandas to xarray, and the only feature that I am really missing is the ability to seamlessly save arrays of python objects to hdf5 (or netCDF). This might be an issue for the backend netCDF4 libraries instead, but I thought I would post it here first to see what the opinions were about this functionality.
For context, Pandas allows this by using pytables'
ObjectAtom
to serialize the object using pickle, then saves as a variable length bytes data type. It is already possible to do this using netCDF4, by applying to each object in the arraynp.fromstring(pickle.dumps(obj), dtype=np.uint8)
, and saving these using a uint8 VLType. Then retrieving is simplypickle.reads(obj.tostring())
for each array.I know pickle can be a security problem, it can cause an problem if you try to save a numerical array that accidently has dtype=object (pandas gives a warning), and that this is probably quite slow (I think pandas pickles a list containing all the objects for speed), but it would be incredibly convenient.
The text was updated successfully, but these errors were encountered: