Describe the bug
Serializing a transformed Regular axis turns it into a Variable axis instead of a Regular with the appropriate transformation.
Steps to reproduce
import json
import boost_histogram as bh
from boost_histogram.serialization._axis import _axis_from_dict, _axis_to_dict
import hist
axis = bh.axis.Regular(
5,
1,
10,
transform=bh.axis.transform.log,
)
print("original:", axis)
print("original type:", type(axis))
print("original transform:", axis.transform)
axis_dict = _axis_to_dict(axis)
print("serialized dict:", json.dumps(axis_dict, indent=2, default=str))
restored = _axis_from_dict(axis_dict)
print("restored:", restored)
print("restored type:", type(restored))
print("restored transform:", getattr(restored, "transform", None))
yields:
original: Regular(5, 1, 10, transform=log)
original type: <class 'boost_histogram.axis.Regular'>
original transform: log
serialized dict: {
"type": "variable",
"edges": "[ 1. 1.58489319 2.51188643 3.98107171 6.30957344 10. ]",
"underflow": true,
"overflow": true,
"circular": false
}
restored: Variable([1, 1.58489, 2.51189, 3.98107, 6.30957, 10])
restored type: <class 'boost_histogram.axis.Variable'>
restored transform: None
My intuition was that the type is always preserved in serialization roundtrips, but maybe that was a deliberate design decision to exclude transforms from serialization and thus Variable axis is the only way to reconstruct the axis correctly?
Describe the bug
Serializing a transformed Regular axis turns it into a Variable axis instead of a Regular with the appropriate transformation.
Steps to reproduce
yields:
My intuition was that the type is always preserved in serialization roundtrips, but maybe that was a deliberate design decision to exclude transforms from serialization and thus Variable axis is the only way to reconstruct the axis correctly?