File tree 2 files changed +17
-5
lines changed
2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -478,10 +478,20 @@ class Data:
478
478
For more information, take a look at this example notebook
479
479
https://docs.pymc.io/notebooks/data_container.html
480
480
"""
481
- def __new__ (self , name , value ):
481
+ def __new__ (self , name , value , dtype = None ):
482
+ if dtype is None :
483
+ if hasattr (value , 'dtype' ):
484
+ # if no dtype given, but available as attr of value, use that as dtype
485
+ dtype = value .dtype
486
+ elif isinstance (value , int ):
487
+ dtype = int
488
+ else :
489
+ # otherwise, assume float
490
+ dtype = float
491
+
482
492
# `pm.model.pandas_to_array` takes care of parameter `value` and
483
493
# transforms it to something digestible for pymc3
484
- shared_object = theano .shared (pm .model .pandas_to_array (value ), name )
494
+ shared_object = theano .shared (pm .model .pandas_to_array (value , dtype = dtype ), name )
485
495
486
496
# To draw the node for this variable in the graphviz Digraph we need
487
497
# its shape.
Original file line number Diff line number Diff line change @@ -1473,7 +1473,7 @@ def init_value(self):
1473
1473
return self .tag .test_value
1474
1474
1475
1475
1476
- def pandas_to_array (data ):
1476
+ def pandas_to_array (data , dtype = float ):
1477
1477
if hasattr (data , 'values' ): # pandas
1478
1478
if data .isnull ().any ().any (): # missing values
1479
1479
ret = np .ma .MaskedArray (data .values , data .isnull ().values )
@@ -1492,8 +1492,10 @@ def pandas_to_array(data):
1492
1492
ret = generator (data )
1493
1493
else :
1494
1494
ret = np .asarray (data )
1495
- return pm .floatX (ret )
1496
-
1495
+ if dtype in [float , np .float32 , np .float64 ]:
1496
+ return pm .floatX (ret )
1497
+ elif dtype in [int , np .int32 , np .int64 ]:
1498
+ return pm .intX (ret )
1497
1499
1498
1500
def as_tensor (data , name , model , distribution ):
1499
1501
dtype = distribution .dtype
You can’t perform that action at this time.
0 commit comments