matthewwardrop / formulaic

A high-performance implementation of Wilkinson formulas for Python.
MIT License
345 stars 25 forks source link

ENH: Add pickle support to ModelMatrix and FactorValues #209

Closed bashtage closed 2 days ago

bashtage commented 3 days ago

Add __reduce__ex__ to classes using ObjectProxy Add tests of equivalence

bashtage commented 3 days ago

pickling of ModelMatrix is needed in statsmodels to match current patsy behavior.

bashtage commented 3 days ago

hatch fmt seems to have gone a bit haywire

bashtage commented 3 days ago

Better after running black and a few manual fixes.

matthewwardrop commented 2 days ago

Thanks for the patch @bashtage !

I simplified it down a little (just used the class constructors rather than a new method), and fixed some new typing conventions that would have broken in older versions of Python. But otherwise looked good!

Also, for formatting you can use: hatch run lint:format. I think hatch added fmt functionality after I set this up, so I might need to update it... but I'm eying moving to uv too.

bashtage commented 2 days ago

3.13 waa the reason for the constructors. Not sure if this is a bug in 3.13 but tests fail using the obvious reduce style.

matthewwardrop commented 2 days ago

Ah! I should have realised you had a reason for this! Sorry! I'll look into this soon.

matthewwardrop commented 2 days ago

Looks like this is due to changes in Python 3.13 that affect wrapt's ObjectProxy. It is fixed in 1.17, which should be released shortly. For now I'll just bump the dependency in formulaic for Python 3.13 to require wrapt 1.17.0rc1 or later.