add support for object values#77
Conversation
|
Dang it, I don't get how I keep missing my GitHub notifications! 😅 |
| let size = match size.parse() { | ||
| Err(e) => bail!(ParseIntError(e)), // probably overflow | ||
| Ok(v) => v, | ||
| let size = if type_char == TypeChar::Empty { |
There was a problem hiding this comment.
the code will bail with a SyntaxError now
|
I'm not sure I understand. The PR says it adds support for "Empty" types, but then talks about pickled objects. It would seem to me that Part of me is tempted to say that if |O has a dynamic length, then perhaps the "size" of a format string should be Option... though this would be a breaking change. I'm interested in seeing an example of how this could be used. In particular I am wondering if the downstream code would have to be using TypeStr, or if this addition allows other parts |
Good point. I renamed it to
I personally don't see the need to make it an option. If you want to support
My downstream code uses |
|
I see! If I'm picturing correctly how you're using it, it sounds like it might actually be pretty simple to write an example that can Deserialize/Serialize an array of pickled objects. This could be a great example to have. |
Pickeld values are stored with a "|O" TypeStr.
|
i've added an example with |
|
Changing the public I think I've got all the pieces I need now, I'll take it from here. |
|
Oh, dang, I wish you had kept those as separate commits. c0f214a would be a better starting point for me but IDK if it will correctly recognize this PR as merged (or you as contributor) if I start from there now. I'll figure something out. |
|
serde_pickle is 1.0 and looks safe to have as a public dependency, so I'm actually going to add a feature for this and provide adaptors anyone can use. |
|
........................................... Uhhhh................. So.... presumably in order to save space on declarations of types and attribute names, whenever serializing an array involves any pickling at all, it pickles the entire ndarray as a single object. It still has a header giving a shape and everything, but after the header there is only a single pickle, not one pickle for each item. This is also true for structured dtypes with an Object hiding somewhere inside them. Which, like....... all of this completely breaks the entire API of this crate, and so just about nearly everything I worked on today to add to this PR has been a colossal waste of time. 😅 TypeRead/TypeWrite adapters for serde_pickle, npyz trait impls for serde_pickle Value, and plenty of documentation is all garbo. It's looking like the feature really can only be the following:
Uggg |
Since the field is an
yes, but seams not maintained - i didn't get any response for my PR so far
sorry to hear that and not being more clear about how it works upfront. i'm not sure how you see the scope for this crate, but adding full decoding support for pickled values seams like a completely different API to me. i'd be happy to see support for this (since i'd need it), but as you wrote yourself it would break nearly the whole crate as it is. IMO the easy way forward, would be to to just add the parsing/writing support for the header and then let the user do whatever they want to do with the body - similar to what i do in the example. is there anything i can help with? |
|
Okay I've almost got everything ironed out now. I'll be pushing something for you to take a look very soon. There is one small thing making it a major semver bump. |
|
Please take a look at #82 and see if you have any comments before I merge |
|
Huh. It didn't auto detect this as merged. Probably because of using "rebase and merge" on the other. It did give @paroga the contributor badge though, so I can close this one. |
|
0.9.0 released |
Pickeld values are stored with a "|O" TypeStr.
Todo: (added by owner)
examplethat shows an array being serialized/deserialized through pickle.NpyHeader::item_sizeshould become an Option. This is an internal change and doesn't impact users.has_known_sizebool, but that's exactly the same in terms of storage, and would only have a performance benefit onNpyData::get_unchecked...)seek_toandread_atmethods.NpyDatahasget,get_unchecked. These cannot really work for|Oand we need to think of what they should do (Err or panic?).NpyData::from_byteshas an assertion that would need adjustment. Luckily these all useNpyHeader::item_size.from_bytes)get_uncheckedis UB, the rest returnErr(exceptfrom_bytes)type_matchup_docsshould mention|O.TypeStr::size_fieldshould mention|Ojust like how it mentionsU.pickle array example and not just a scalar.Ocorrectly"a4"without the|endianness marker should be supported #81 . It affects O too.