Skip to content

Commit 135fb37

Browse files
committed
Rename pandas_to_array to convert_observed_data
1 parent c76b9b9 commit 135fb37

File tree

5 files changed

+16
-19
lines changed

5 files changed

+16
-19
lines changed

pymc/aesaraf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,13 @@
8181
"set_at_rng",
8282
"at_rng",
8383
"take_along_axis",
84-
"pandas_to_array",
84+
"convert_observed_data",
8585
]
8686

8787

88-
def pandas_to_array(data):
89-
"""Convert a pandas object to a NumPy array.
88+
def convert_observed_data(data):
89+
"""Convert user provided dataset to accepted formats."""
9090

91-
XXX: When `data` is a generator, this will return an Aesara tensor!
92-
93-
"""
9491
if hasattr(data, "to_numpy") and hasattr(data, "isnull"):
9592
# typically, but not limited to pandas objects
9693
vals = data.to_numpy()

pymc/data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
import pymc as pm
3535

36-
from pymc.aesaraf import pandas_to_array
36+
from pymc.aesaraf import convert_observed_data
3737

3838
__all__ = [
3939
"get_data",
@@ -636,9 +636,9 @@ def Data(
636636
)
637637
name = model.name_for(name)
638638

639-
# `pandas_to_array` takes care of parameter `value` and
639+
# `convert_observed_data` takes care of parameter `value` and
640640
# transforms it to something digestible for Aesara.
641-
arr = pandas_to_array(value)
641+
arr = convert_observed_data(value)
642642

643643
if mutable is None:
644644
major, minor = (int(v) for v in pm.__version__.split(".")[:2])

pymc/distributions/shape_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from aesara.tensor.var import TensorVariable
2727
from typing_extensions import TypeAlias
2828

29-
from pymc.aesaraf import pandas_to_array
29+
from pymc.aesaraf import convert_observed_data
3030

3131
__all__ = [
3232
"to_tuple",
@@ -558,7 +558,7 @@ def resize_from_observed(
558558
Observations as numpy array or `Variable`.
559559
"""
560560
if not hasattr(observed, "shape"):
561-
observed = pandas_to_array(observed)
561+
observed = convert_observed_data(observed)
562562
ndim_resize = observed.ndim - ndim_implied
563563
resize_shape = tuple(observed.shape[d] for d in range(ndim_resize))
564564
return resize_shape, observed

pymc/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050

5151
from pymc.aesaraf import (
5252
compile_pymc,
53+
convert_observed_data,
5354
gradient,
5455
hessian,
5556
inputvars,
56-
pandas_to_array,
5757
rvs_to_value_vars,
5858
)
5959
from pymc.blocking import DictToArrayBijection, RaveledVars
@@ -1158,7 +1158,7 @@ def set_data(
11581158

11591159
if isinstance(values, list):
11601160
values = np.array(values)
1161-
values = pandas_to_array(values)
1161+
values = convert_observed_data(values)
11621162
dims = self.RV_dims.get(name, None) or ()
11631163
coords = coords or {}
11641164

@@ -1290,7 +1290,7 @@ def make_obs_var(
12901290
12911291
"""
12921292
name = rv_var.name
1293-
data = pandas_to_array(data).astype(rv_var.dtype)
1293+
data = convert_observed_data(data).astype(rv_var.dtype)
12941294

12951295
if data.ndim != rv_var.ndim:
12961296
raise ShapeError(

pymc/tests/test_aesaraf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
_conversion_map,
3939
change_rv_size,
4040
compile_pymc,
41+
convert_observed_data,
4142
extract_obs_data,
42-
pandas_to_array,
4343
rvs_to_value_vars,
4444
take_along_axis,
4545
walk_model,
@@ -413,9 +413,9 @@ def test_extract_obs_data():
413413

414414

415415
@pytest.mark.parametrize("input_dtype", ["int32", "int64", "float32", "float64"])
416-
def test_pandas_to_array(input_dtype):
416+
def test_convert_observed_data(input_dtype):
417417
"""
418-
Ensure that pandas_to_array returns the dense array, masked array,
418+
Ensure that convert_observed_data returns the dense array, masked array,
419419
graph variable, TensorVariable, or sparse matrix as appropriate.
420420
"""
421421
pd = pytest.importorskip("pandas")
@@ -437,7 +437,7 @@ def test_pandas_to_array(input_dtype):
437437
square_generator = (np.array([i**2], dtype=int) for i in range(100))
438438

439439
# Alias the function to be tested
440-
func = pandas_to_array
440+
func = convert_observed_data
441441

442442
#####
443443
# Perform the various tests
@@ -496,7 +496,7 @@ def test_pandas_to_array(input_dtype):
496496
def test_pandas_to_array_pandas_index():
497497
pd = pytest.importorskip("pandas")
498498
data = pd.Index([1, 2, 3])
499-
result = pandas_to_array(data)
499+
result = convert_observed_data(data)
500500
expected = np.array([1, 2, 3])
501501
np.testing.assert_array_equal(result, expected)
502502

0 commit comments

Comments
 (0)