Serialize instances of scipy rv_continuous and rv_discrete subclasses

I use distribution classes in scipy.stats.distributionsand you need to serialize instances for storage and transfer. These are quite complex objects, and they do not quarrel. I'm trying to develop a mixin class that makes objects legible so that I can work with remarketing subclasses that otherwise behave the same as objects from scipy.stats. The more I investigate the problem, the more I get confused, and I wonder if I am missing an obvious way to do this.

I read a related question about how to expose instance methods, but this is only part of the general solution that I need and which may not even be needed. I experimented with writing brine support functions that closely follow the method __init__and serialize the object as arguments to __init__, but this seems fragile, especially if subclasses can define arbitrary behavior of the subclass in __init__.

Does anyone have an elegant sharing solution?

Update: I found a Python bug report with an example of registering brine support functions using the copy_regmodule to parse instance methods. For my case, the instance method attributes were the only blockers. However, I would still like to know if there is a way to use the mixin class to solve this problem, because it copy_reghas global effects that may be undesirable in all situations.

+3
source share

Source: https://habr.com/ru/post/1790640/


All Articles