-
Notifications
You must be signed in to change notification settings - Fork 71
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
Several improvements concerning dicts, passing open HDF5-files and more #94
Conversation
Removed use of ModuleNotFoundError, as it was introduced in Python 3.6 and therefore incompatible with Python 3.5. However, since it is a subclass of ImportError, catching ImportError will also catch ModuleNotFoundError.
…n hickle.py. Fixed problem with HDF5-files not being closed properly during dump if an error was raised.
…utomatically closes it. If any errors are raised during hickle.dump or hickle.load, the file is automatically closed unless it was already open. Set the working directory for running tests to the operating system's temporary directory (this also allows for all os.remove statements to be removed). Written tests for the new features.
Removed all cases of using os.remove() or any file removal, as files are now created in the temporary directory of the system (which is emptied automatically by either the computer or pytest).
The dtype of a dict is now always properly saved (before, it was sometimes saved as a binary type and sometimes as a normal type). Added tests for checking if empty dicts are unhickled properly. Using tuples as dict keys will currently raise an error when loading it back in (I am working on a fix).
Written tests for the new functionalities.
Actually, you may want to wait with accepting the PR, as I'm planning on doing one final upgrade to the keys of dicts, which will allow for both |
… (in which case they are saved as double strings). Dict keys are now converted back to their original type using the eval()-function (which converts everything to what it used to be if it was a string to begin with). Added tests for the new functionalities.
…t[:], as this works in both cases and the latter is deprecated.
Thanks, looks like there's some great stuff here! I am however going to push back against the use of That said, loading pickles is in itself dangerous if you didn't make it yourself, e.g. in the
As hickle loads data mapped from HDF5, it should in theory be much safer*. There is however in I think in this case, the cons of using * Of course, don't trust any code! Obligatory disclaimers in the LICENSE. |
@telegraphic I was considering ACE as well, but it is not possible to create a dataset with a key that is a tuple but in reality is not. But, I will have a look at it. |
Thanks, hope you're having fun ;). It's was a learning experience for me dealing with bug reports due to weird & wonderful use cases I didn't think of (or even know you could do)! It's a bit of a balancing act to find sensible ways to map between Python and HDF5 data structures. |
Oh, I am having fun with this. |
Good question, difficult to answer! I think an estimate of likelihood of use case is required. As little as possible? For example, I can certainly see use cases where you have tuple indexes all of the same type, e.g. If you do find use cases that really really need There is very basic support for registering a new class to hickle, which gives a path to allow users to add their own creations, but this is still limited and won't necessarily override default handling of e.g. |
I actually have a case where I am using tuples that have integers, floats and strings in them. |
Alright, I have currently removed using the |
Alright, I just found out about the |
…_eval function, which cannot execute anything that is not a Python object.
Thanks @1313e, |
@telegraphic Would it be possible to generate a new release for PyPI, such that I can update the requirements in PRISM and make a new version there as well? |
sure thing, just rerunning tests, the scipy sparse_matrix test is failing for some reason on Py 3.5 and 3.7 (but not Py 2.7 or 3.7), even though PR passed |
I have been having some issues with Travis lately as well, where it was simply giving me errors about timing out or something. |
Ugh, it is |
You may want to set a minimum required version for NumPy, as I get the feeling that that is the problem (it raises errors of NumPy 1.7, which was released a very long time ago). |
@1313e -- I think this is an upstream bug, so pushed to PyPi |
@telegraphic I saw it, thanks. |
@telegraphic Also, if you need some help with Python2/Python3 compatibility (especially strings) or anything else, let me know. |
Several improvements concerning dicts, passing open HDF5-files and more
This PR contains the following changes:
hickle.py
;1
and'1'
) can now be properly hickled and unhickled;h5py.File
object tohickle.dump
andhickle.load
will no longer automatically close the file ( [FEATURE] Providing an open HDF5-file to dump/load does not close the file #92 );hickle.dump
orhickle.load
, an opened HDF5-file is always closed, unless it was provided as open to these functions (that is the user's task obviously) ( Hickling NumPy arrays with dtypes that are not supported by h5py #90 );os.remove
uses in the tests, aspytest
or your own machine automatically performs clean-ups in the temporary directory;I have tried to remain as true as possible to the original style of coding (except I use parenthesis for
return
, since I hate using it as a statement).All changes should be backwards compatible, except for hickled dicts that had their dtype saved incorrectly.