-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
Description of your problem
Aesara can not convert pandas dataframes into tensors. @twiecki suggested me to open an issue about it here :)
Please provide a minimal, self-contained, and reproducible example.
import aesara.tensor as at
import pandas as pd
df = pd.DataFrame(data={"col": [1.0, 2.0, -1.0]})
at.as_tensor(x=df, name="df")
Please provide the full traceback.
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
/Users/juanitorduz/Documents/offline_channels_marketing_efficiency/JPN/notebooks/geo-tests/pre_test_analysis.ipynb Cell 42' in <cell line: 6>()
[2](vscode-notebook-cell:/Users/juanitorduz/Documents/offline_channels_marketing_efficiency/JPN/notebooks/geo-tests/pre_test_analysis.ipynb#ch0000042?line=1) import pandas as pd
[4](vscode-notebook-cell:/Users/juanitorduz/Documents/offline_channels_marketing_efficiency/JPN/notebooks/geo-tests/pre_test_analysis.ipynb#ch0000042?line=3) df = pd.DataFrame(data={"col": [1.0, 2.0, -1.0]})
----> [6](vscode-notebook-cell:/Users/juanitorduz/Documents/offline_channels_marketing_efficiency/JPN/notebooks/geo-tests/pre_test_analysis.ipynb#ch0000042?line=5) at.as_tensor(x=df, name="df")
File ~/.local/share/virtualenvs/offline_channels_marketing_efficiency-hd9wNcdu/lib/python3.8/site-packages/aesara/tensor/__init__.py:42, in as_tensor_variable(x, name, ndim, **kwargs)
10 def as_tensor_variable(
11 x: Any, name: Optional[str] = None, ndim: Optional[int] = None, **kwargs
12 ) -> "TensorVariable":
13 """Convert `x` into an equivalent `TensorVariable`.
14
15 This function can be used to turn ndarrays, numbers, `ScalarType` instances,
(...)
40
41 """
---> 42 return _as_tensor_variable(x, name, ndim, **kwargs)
File ~/opt/anaconda3/lib/python3.8/functools.py:875, in singledispatch.<locals>.wrapper(*args, **kw)
871 if not args:
872 raise TypeError(f'{funcname} requires at least '
873 '1 positional argument')
--> 875 return dispatch(args[0].__class__)(*args, **kw)
File ~/.local/share/virtualenvs/offline_channels_marketing_efficiency-hd9wNcdu/lib/python3.8/site-packages/aesara/tensor/__init__.py:49, in _as_tensor_variable(x, name, ndim, **kwargs)
45 @singledispatch
46 def _as_tensor_variable(
47 x, name: Optional[str], ndim: Optional[int], **kwargs
48 ) -> "TensorVariable":
---> 49 raise NotImplementedError(f"Cannot convert {x} to a tensor variable.")
NotImplementedError: Cannot convert col
0 1.0
1 2.0
2 -1.0 to a tensor variable.
If I convert to numpy
it works as expected:
at.as_tensor(x=df.to_numpy(), name="df")
Please provide any additional information below.
Versions and main components
- PyMC/PyMC3 Version:
pymc==4.0.0
- Aesara/Theano Version:
aesara==2.6.6
- Python Version: 3.8
- Operating system: MacOS
- How did you install PyMC/PyMC3: (conda/pip) Pipenv