Closed daffidwilde closed 4 years ago
This PR moves some of the internal functionality away from the Distribution class and into the dynamic <Family.distribution.name>Subtype type. Namely:
Distribution
<Family.distribution.name>Subtype
pandas.DataFrame.to_csv
json.dump
Subtype
Individual.metadata
Example:
>>> import numpy as np >>> import pandas as pd >>> >>> from edo import Family >>> from edo.distributions import Uniform, Poisson >>> from edo.individual import Individual >>> >>> np.random.seed(0) >>> distributions = [Uniform, Poisson] >>> families = [Family(dist) for dist in distributions] >>> >>> metadata = [family.make_instance() for family in families] >>> dataframe = pd.DataFrame({i: meta.sample(5) for i, meta in enumerate(metadata)}) >>> individual = Individual(dataframe, metadata) >>> >>> individual.to_file("individual/") PosixPath('individual') >>> >>> saved = Individual.from_file(distributions, "individual/") >>> >>> np.allclose(saved.dataframe.values, individual.dataframe.values) True >>> saved.metadata, individual.metadata ([Uniform(bounds=[0.98, 4.3]), Poisson(lam=6.03)], [Uniform(bounds=[0.98, 4.3]), Poisson(lam=6.03)])
This PR moves some of the internal functionality away from the
Distribution
class and into the dynamic<Family.distribution.name>Subtype
type. Namely:pandas.DataFrame.to_csv
andjson.dump
for the dataframe and metadata respectively.Subtype
instances inIndividual.metadata
are converted to dictionaries that can be restored.Example: