ezmsg-org / ezmsg

Pure-Python DAG-based high-performance SHM-backed pub-sub and multi-processing pattern
https://ezmsg.readthedocs.io/en/latest/
MIT License
15 stars 6 forks source link

[For Discussion] Should AxisArray.axes be a frozendict? #125

Open cboulay opened 5 months ago

cboulay commented 5 months ago

As mentioned in ezmsg-org/ezmsg-sigproc#7 , I sometimes bungle the AxisArray creation / copying / manipulation and end up mutating an object that is referenced elsewhere. At least some of my mistakes could have been prevented if AxisArray's .axes field was a frozendict. I understand the hesitation to bring in a 3rd party dependency so I won't push on this at all, but if not frozendict then it would be nice if there was another way to prevent mutating .axes.

griffinmilsap commented 5 months ago

agreed, and also manipulating AxisArrays is a bit of a pain in general. I don't like .ax and .axes etc.. I need to put some time into an axisarray refactor including a basic coords impl. soon

cboulay commented 2 months ago

Just for fun (?), I made all the ezmsg-sigproc unit tests use frozendict when creating new AxisArray messages: https://github.com/ezmsg-org/ezmsg-sigproc/pull/20

All the tests still pass! So if we do decide to add frozendict as a dependency to ezmsg, at least we know it should integrate seamlessly.

cboulay commented 5 days ago

If we don't want to include a 3rd-party dependency, then we can try MappingProxyType instead.

Here are differences between MappingProxyType and frozendict according to the maintainer of frozendict.