Skip to content

Pass kwargs from pm.Data to aesara.shared #5098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ This includes API changes we did not warn about since at least `3.11.0` (2021-01
- New features for BART:
- Added linear response, increased number of trees fitted per step [5044](https://github.com/pymc-devs/pymc3/pull/5044).
- Added partial dependence plots and individual conditional expectation plots [5091](https://github.com/pymc-devs/pymc3/pull/5091).
- `pm.Data` now passes additional kwargs to `aesara.shared`. [#5098](https://github.com/pymc-devs/pymc/pull/5098)
- ...


Expand Down
20 changes: 15 additions & 5 deletions pymc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,8 @@ def align_minibatches(batches=None):


class Data:
"""Data container class that wraps the Aesara ``SharedVariable`` class
and lets the model be aware of its inputs and outputs.
"""Data container class that wraps :func:`aesara.shared` and lets
the model be aware of its inputs and outputs.

Parameters
----------
Expand All @@ -478,10 +478,12 @@ class Data:
random variables). Use this when `value` is a pandas Series or DataFrame. The
`dims` will then be the name of the Series / DataFrame's columns. See ArviZ
documentation for more information about dimensions and coordinates:
https://arviz-devs.github.io/arviz/notebooks/Introduction.html
:ref:`arviz:quickstart`.
export_index_as_coords: bool, optional, default=False
If True, the `Data` container will try to infer what the coordinates should be
if there is an index in `value`.
**kwargs: dict, optional
Extra arguments passed to :func:`aesara.shared`.

Examples
--------
Expand Down Expand Up @@ -512,7 +514,15 @@ class Data:
https://docs.pymc.io/notebooks/data_container.html
"""

def __new__(self, name, value, *, dims=None, export_index_as_coords=False):
def __new__(
self,
name,
value,
*,
dims=None,
export_index_as_coords=False,
**kwargs,
):
if isinstance(value, list):
value = np.array(value)

Expand All @@ -528,7 +538,7 @@ def __new__(self, name, value, *, dims=None, export_index_as_coords=False):

# `pandas_to_array` takes care of parameter `value` and
# transforms it to something digestible for pymc
shared_object = aesara.shared(pandas_to_array(value), name)
shared_object = aesara.shared(pandas_to_array(value), name, **kwargs)

if isinstance(dims, str):
dims = (dims,)
Expand Down
13 changes: 13 additions & 0 deletions pymc/tests/test_data_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ def test_implicit_coords_dataframe(self):
assert "columns" in pmodel.coords
assert pmodel.RV_dims == {"observations": ("rows", "columns")}

def test_data_kwargs(self):
strict_value = True
allow_downcast_value = False
with pm.Model():
data = pm.Data(
"data",
value=[[1.0], [2.0], [3.0]],
strict=strict_value,
allow_downcast=allow_downcast_value,
)
assert data.container.strict is strict_value
assert data.container.allow_downcast is allow_downcast_value


def test_data_naming():
"""
Expand Down