Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ejolly committed Sep 7, 2023
1 parent 12bcb2e commit efaac0f
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ conda/build_main/*
.venv
environment.yml
*.pickle
*.joblib
Binary file modified docs/auto_examples/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified docs/auto_examples/auto_examples_python.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/auto_examples/example_01_basic_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model Persistence\nAll pymer4 models can be saved and loaded from disk. Doing so will persist *all* model attributes and data i.e. anything accessible with the '.' syntax. Models are saved and loaded using [Joblib](https://joblib.readthedocs.io/en/latest/persistence.html#persistence) Therefore all filenames must end with :code:`.joblib`. For :code:`Lmer` models, an additional file ending in :code:`.rds` will be saved in the same directory as the HDF5 file. This is the R model object readable in R using :code:`readRDS`.\n\nPrior to version 0.8.1 models were saved to HDF5 files using [deepdish](https://github.com/uchicago-cs/deepdish/) but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models. \n\nTo persist models you can use the dedicated :code:`save_model` and :code:`load_model` functions from the :code:`pymer4.io` module\n\n"
"## Model Persistence\nAll pymer4 models can be saved and loaded from disk. Doing so will persist *all* model attributes and data i.e. anything accessible with the '.' syntax. Models are saved and loaded using [Joblib](https://joblib.readthedocs.io/en/latest/persistence.html#persistence) Therefore all filenames must end with :code:`.joblib`. For :code:`Lmer` models, an additional file ending in :code:`.rds` will be saved in the same directory as the HDF5 file. This is the R model object readable in R using :code:`readRDS`.\n\nPrior to version 0.8.1 models were saved to HDF5 files using [deepdish](https://github.com/uchicago-cs/deepdish/) but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.\n\nTo persist models you can use the dedicated :code:`save_model` and :code:`load_model` functions from the :code:`pymer4.io` module\n\n"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/auto_examples/example_01_basic_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
# -----------------
# All pymer4 models can be saved and loaded from disk. Doing so will persist *all* model attributes and data i.e. anything accessible with the '.' syntax. Models are saved and loaded using `Joblib <https://joblib.readthedocs.io/en/latest/persistence.html#persistence>`_ Therefore all filenames must end with :code:`.joblib`. For :code:`Lmer` models, an additional file ending in :code:`.rds` will be saved in the same directory as the HDF5 file. This is the R model object readable in R using :code:`readRDS`.
#
# Prior to version 0.8.1 models were saved to HDF5 files using `deepdish <https://github.com/uchicago-cs/deepdish/>`_ but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.
#
# Prior to version 0.8.1 models were saved to HDF5 files using `deepdish <https://github.com/uchicago-cs/deepdish/>`_ but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.
#
# To persist models you can use the dedicated :code:`save_model` and :code:`load_model` functions from the :code:`pymer4.io` module

# Import functions
Expand Down
2 changes: 1 addition & 1 deletion docs/auto_examples/example_01_basic_usage.py.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
710973e4fa57fe480157e222e5f8a970
b56f42c7a0051017f9fba41a12809193
2 changes: 1 addition & 1 deletion docs/auto_examples/example_01_basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ Model Persistence
-----------------
All pymer4 models can be saved and loaded from disk. Doing so will persist *all* model attributes and data i.e. anything accessible with the '.' syntax. Models are saved and loaded using `Joblib <https://joblib.readthedocs.io/en/latest/persistence.html#persistence>`_ Therefore all filenames must end with :code:`.joblib`. For :code:`Lmer` models, an additional file ending in :code:`.rds` will be saved in the same directory as the HDF5 file. This is the R model object readable in R using :code:`readRDS`.

Prior to version 0.8.1 models were saved to HDF5 files using `deepdish <https://github.com/uchicago-cs/deepdish/>`_ but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.
Prior to version 0.8.1 models were saved to HDF5 files using `deepdish <https://github.com/uchicago-cs/deepdish/>`_ but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.

To persist models you can use the dedicated :code:`save_model` and :code:`load_model` functions from the :code:`pymer4.io` module

Expand Down
Binary file modified docs/auto_examples/images/sphx_glr_example_01_basic_usage_001.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/images/sphx_glr_example_01_basic_usage_002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/auto_examples/images/sphx_glr_example_01_basic_usage_004.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/auto_examples/sg_execution_times.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

Computation times
=================
**00:02.603** total execution time for **auto_examples** files:
**00:02.957** total execution time for **auto_examples** files:

+-------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_example_01_basic_usage.py` (``example_01_basic_usage.py``) | 00:02.603 | 0.0 MB |
| :ref:`sphx_glr_auto_examples_example_01_basic_usage.py` (``example_01_basic_usage.py``) | 00:02.957 | 0.0 MB |
+-------------------------------------------------------------------------------------------------+-----------+--------+
| :ref:`sphx_glr_auto_examples_example_02_categorical.py` (``example_02_categorical.py``) | 00:00.000 | 0.0 MB |
+-------------------------------------------------------------------------------------------------+-----------+--------+
Expand Down
9 changes: 9 additions & 0 deletions docs/new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ What's New
==========
Historically :code:`pymer4` versioning was a bit all over the place but has settled down since 0.5.0. This page includes the most notable updates between versions but github is the best place to checkout more details and `releases <https://github.com/ejolly/pymer4/releases/>`_.

0.8.1
----
- **NOTE:**
- This version drops support for Python 3.7 and adds support for 3.9-3.11
- This version also uses :code:`joblib` for model saving and loading and drops supported hdf5 files previously handled with :code:`deepdish` (no longer maintained). This version will no longer be able to load models saved with versions < 0.8.1
- fixes `#122 <https://github.com/ejolly/pymer4/issues/122>`_
- fixes `#125 <https://github.com/ejolly/pymer4/issues/125>`_
- fixes `#119 <https://github.com/ejolly/pymer4/issues/119>`_

0.8.0
----
- **NOTE:**
Expand Down
4 changes: 2 additions & 2 deletions examples/example_01_basic_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
# -----------------
# All pymer4 models can be saved and loaded from disk. Doing so will persist *all* model attributes and data i.e. anything accessible with the '.' syntax. Models are saved and loaded using `Joblib <https://joblib.readthedocs.io/en/latest/persistence.html#persistence>`_ Therefore all filenames must end with :code:`.joblib`. For :code:`Lmer` models, an additional file ending in :code:`.rds` will be saved in the same directory as the HDF5 file. This is the R model object readable in R using :code:`readRDS`.
#
# Prior to version 0.8.1 models were saved to HDF5 files using `deepdish <https://github.com/uchicago-cs/deepdish/>`_ but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.
#
# Prior to version 0.8.1 models were saved to HDF5 files using `deepdish <https://github.com/uchicago-cs/deepdish/>`_ but this library is no longer maintained. If you have old models saved as :code:`.h5` or :code:`.hdf5` files you should use the same version of pymer4 that you used to estimate those models.
#
# To persist models you can use the dedicated :code:`save_model` and :code:`load_model` functions from the :code:`pymer4.io` module

# Import functions
Expand Down
7 changes: 4 additions & 3 deletions pymer4/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def save_model(model, filepath, **kwargs):
"""

filepath = str(filepath)
if not filepath.endswith('.joblib'):
if not filepath.endswith(".joblib"):
raise IOError("filepath must end with .joblib")

rds_file = filepath.replace(".joblib", ".rds")

# Save the python object
dump(model, filepath, **kwargs)
assert os.path.exists(filepath)
Expand All @@ -34,6 +34,7 @@ def save_model(model, filepath, **kwargs):
base.saveRDS(model.model_obj, rds_file)
assert os.path.exists(rds_file)


def load_model(filepath):
"""
Function for loading pymer4 models. A file path ending in .joblib should be provided. For Lmer models an additional filepath.robj should be located in the same directory.
Expand All @@ -44,7 +45,7 @@ def load_model(filepath):
"""

filepath = str(filepath)
if not filepath.endswith('.joblib'):
if not filepath.endswith(".joblib"):
raise IOError("filepath must end with .joblib")

rds_file = filepath.replace(".joblib", ".rds")
Expand Down
11 changes: 6 additions & 5 deletions pymer4/tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from pymer4.models import Lm, Lm2, Lmer
from pymer4.io import load_model, save_model


def test_saveload_lmer(df, tmp_path):

model = Lmer("DV ~ IV3 + IV2 + (IV2|Group) + (1|IV3)", data=df)
model.fit(summarize=False)
output_file = tmp_path / 'model.joblib'
rds_file = tmp_path / 'model.rds'
output_file = tmp_path / "model.joblib"
rds_file = tmp_path / "model.rds"

save_model(model, output_file)
assert output_file.exists()
Expand All @@ -21,7 +22,7 @@ def test_saveload_lm(df, tmp_path):

model = Lm("DV ~ IV1 + IV3", data=df)
model.fit(summarize=False)
output_file = tmp_path / 'model.joblib'
output_file = tmp_path / "model.joblib"

save_model(model, output_file)
assert output_file.exists()
Expand All @@ -35,11 +36,11 @@ def test_saveload_lm2(df, tmp_path):

model = Lm2("DV ~ IV3 + IV2", group="Group", data=df)
model.fit(summarize=False)
output_file = tmp_path / 'model.joblib'
output_file = tmp_path / "model.joblib"

save_model(model, output_file)
assert output_file.exists()

m = load_model(output_file)
assert m.coefs.equals(model.coefs)
assert m.data.equals(model.data)
assert m.data.equals(model.data)

0 comments on commit efaac0f

Please sign in to comment.