frejanordsiek / hdf5storage

Python package to read and write a wide range of Python types to/from HDF5 formatted files. Can read/write data to the HDF5 based Matlab v7.3 MAT files.
BSD 2-Clause "Simplified" License
83 stars 24 forks source link

Adding support for fractions.Fraction #93

Closed frejanordsiek closed 4 years ago

frejanordsiek commented 4 years ago

Adding read/write support for fractions.Fraction (https://docs.python.org/3/library/fractions.html).

frejanordsiek commented 4 years ago

Added in commit 957df63ae4aadc7c4a3d2e01433971f9cd8f12a9 with the new marshaller Marshallers.PythonFractionMarshaller. It is stored as a dict of its numerator and denominator. Since the fractions module is not used elsewhere in the hdf5storage package, it is not imported by default. Instead it is imported only as needed. This means that Marshallers.PythonFractionMarshaller is a good simple example of how to write a marshaller for a type in a module that should only be loaded as needed.