@@ -66,8 +66,10 @@ def data(self, eight_schools_params, draws, chains):
66
66
67
67
def get_inference_data (self , data , eight_schools_params ):
68
68
with data .model :
69
- prior = pm .sample_prior_predictive ()
70
- posterior_predictive = pm .sample_posterior_predictive (data .obj )
69
+ prior = pm .sample_prior_predictive (return_inferencedata = False )
70
+ posterior_predictive = pm .sample_posterior_predictive (
71
+ data .obj , return_inferencedata = False
72
+ )
71
73
72
74
return (
73
75
to_inference_data (
@@ -85,8 +87,10 @@ def get_predictions_inference_data(
85
87
self , data , eight_schools_params , inplace
86
88
) -> Tuple [InferenceData , Dict [str , np .ndarray ]]:
87
89
with data .model :
88
- prior = pm .sample_prior_predictive ()
89
- posterior_predictive = pm .sample_posterior_predictive (data .obj )
90
+ prior = pm .sample_prior_predictive (return_inferencedata = False )
91
+ posterior_predictive = pm .sample_posterior_predictive (
92
+ data .obj , return_inferencedata = False
93
+ )
90
94
91
95
idata = to_inference_data (
92
96
trace = data .obj ,
@@ -106,7 +110,9 @@ def make_predictions_inference_data(
106
110
self , data , eight_schools_params
107
111
) -> Tuple [InferenceData , Dict [str , np .ndarray ]]:
108
112
with data .model :
109
- posterior_predictive = pm .sample_posterior_predictive (data .obj )
113
+ posterior_predictive = pm .sample_posterior_predictive (
114
+ data .obj , return_inferencedata = False
115
+ )
110
116
idata = predictions_to_inference_data (
111
117
posterior_predictive ,
112
118
posterior_trace = data .obj ,
@@ -199,7 +205,9 @@ def test_predictions_to_idata_new(self, data, eight_schools_params):
199
205
200
206
def test_posterior_predictive_keep_size (self , data , chains , draws , eight_schools_params ):
201
207
with data .model :
202
- posterior_predictive = pm .sample_posterior_predictive (data .obj , keep_size = True )
208
+ posterior_predictive = pm .sample_posterior_predictive (
209
+ data .obj , keep_size = True , return_inferencedata = False
210
+ )
203
211
inference_data = to_inference_data (
204
212
trace = data .obj ,
205
213
posterior_predictive = posterior_predictive ,
@@ -214,7 +222,9 @@ def test_posterior_predictive_keep_size(self, data, chains, draws, eight_schools
214
222
215
223
def test_posterior_predictive_warning (self , data , eight_schools_params , caplog ):
216
224
with data .model :
217
- posterior_predictive = pm .sample_posterior_predictive (data .obj , 370 )
225
+ posterior_predictive = pm .sample_posterior_predictive (
226
+ data .obj , 370 , return_inferencedata = False
227
+ )
218
228
inference_data = to_inference_data (
219
229
trace = data .obj ,
220
230
posterior_predictive = posterior_predictive ,
@@ -375,10 +385,7 @@ def test_multiple_observed_rv_without_observations(self):
375
385
with pm .Model ():
376
386
mu = pm .Normal ("mu" )
377
387
x = pm .DensityDist ( # pylint: disable=unused-variable
378
- "x" ,
379
- mu ,
380
- logp = lambda value , mu : pm .Normal .logp (value , mu , 1 ),
381
- observed = 0.1 ,
388
+ "x" , mu , logp = lambda value , mu : pm .Normal .logp (value , mu , 1 ), observed = 0.1
382
389
)
383
390
inference_data = pm .sample (100 , chains = 2 , return_inferencedata = True )
384
391
test_dict = {
@@ -483,7 +490,9 @@ def test_predictions_constant_data(self):
483
490
y = pm .Data ("y" , [1.0 , 2.0 ])
484
491
beta = pm .Normal ("beta" , 0 , 1 )
485
492
obs = pm .Normal ("obs" , x * beta , 1 , observed = y ) # pylint: disable=unused-variable
486
- predictive_trace = pm .sample_posterior_predictive (inference_data )
493
+ predictive_trace = pm .sample_posterior_predictive (
494
+ inference_data , return_inferencedata = False
495
+ )
487
496
assert set (predictive_trace .keys ()) == {"obs" }
488
497
# this should be four chains of 100 samples
489
498
# assert predictive_trace["obs"].shape == (400, 2)
@@ -506,8 +515,8 @@ def test_no_trace(self):
506
515
beta = pm .Normal ("beta" , 0 , 1 )
507
516
obs = pm .Normal ("obs" , x * beta , 1 , observed = y ) # pylint: disable=unused-variable
508
517
idata = pm .sample (100 , tune = 100 )
509
- prior = pm .sample_prior_predictive ()
510
- posterior_predictive = pm .sample_posterior_predictive (idata )
518
+ prior = pm .sample_prior_predictive (return_inferencedata = False )
519
+ posterior_predictive = pm .sample_posterior_predictive (idata , return_inferencedata = False )
511
520
512
521
# Only prior
513
522
inference_data = to_inference_data (prior = prior , model = model )
@@ -539,7 +548,7 @@ def test_priors_separation(self, use_context):
539
548
y = pm .Data ("y" , [1.0 , 2.0 , 3.0 ])
540
549
beta = pm .Normal ("beta" , 0 , 1 )
541
550
obs = pm .Normal ("obs" , x * beta , 1 , observed = y ) # pylint: disable=unused-variable
542
- prior = pm .sample_prior_predictive ()
551
+ prior = pm .sample_prior_predictive (return_inferencedata = False )
543
552
544
553
test_dict = {
545
554
"prior" : ["beta" , "~obs" ],
@@ -574,10 +583,7 @@ def test_multivariate_observations(self):
574
583
575
584
def test_constant_data_coords_issue_5046 (self ):
576
585
"""This is a regression test against a bug where a local coords variable was overwritten."""
577
- dims = {
578
- "alpha" : ["backwards" ],
579
- "bravo" : ["letters" , "yesno" ],
580
- }
586
+ dims = {"alpha" : ["backwards" ], "bravo" : ["letters" , "yesno" ]}
581
587
coords = {
582
588
"backwards" : np .arange (17 )[::- 1 ],
583
589
"letters" : list ("ABCDEFGHIJK" ),
@@ -592,20 +598,13 @@ def test_constant_data_coords_issue_5046(self):
592
598
assert len (data [k ].shape ) == len (dims [k ])
593
599
594
600
ds = pm .backends .arviz .dict_to_dataset (
595
- data = data ,
596
- library = pm ,
597
- coords = coords ,
598
- dims = dims ,
599
- default_dims = [],
600
- index_origin = 0 ,
601
+ data = data , library = pm , coords = coords , dims = dims , default_dims = [], index_origin = 0
601
602
)
602
603
for dname , cvals in coords .items ():
603
604
np .testing .assert_array_equal (ds [dname ].values , cvals )
604
605
605
606
def test_issue_5043_autoconvert_coord_values (self ):
606
- coords = {
607
- "city" : pd .Series (["Bonn" , "Berlin" ]),
608
- }
607
+ coords = {"city" : pd .Series (["Bonn" , "Berlin" ])}
609
608
with pm .Model (coords = coords ) as pmodel :
610
609
# The model tracks coord values as (immutable) tuples
611
610
assert isinstance (pmodel .coords ["city" ], tuple )
@@ -631,11 +630,7 @@ def test_issue_5043_autoconvert_coord_values(self):
631
630
trace = mtrace ,
632
631
coords = {
633
632
"city" : pd .MultiIndex .from_tuples (
634
- [
635
- ("Bonn" , 53111 ),
636
- ("Berlin" , 10178 ),
637
- ],
638
- names = ["name" , "zipcode" ],
633
+ [("Bonn" , 53111 ), ("Berlin" , 10178 )], names = ["name" , "zipcode" ]
639
634
)
640
635
},
641
636
)
0 commit comments