pytensor
pytensor copied to clipboard
Move pandas converters to pytensor
Description
Does it make sense to move the converters into pytensor? It will be slightly longer import time, but user experience will be better
try:
import pandas as pd
# https://github.com/pymc-devs/pymc/blob/main/pymc/aesaraf.py#L152
@_as_tensor_variable.register(pd.Series)
@_as_tensor_variable.register(pd.DataFrame)
def dataframe_to_tensor_variable(df: pd.DataFrame, *args, **kwargs) -> TensorVariable:
return at.as_tensor_variable(df.to_numpy(), *args, **kwargs)
except ImportError:
pass
Is there a way to do this lazily?
@ricardoV94 This is already in https://github.com/pymc-devs/pymc/blob/main/pymc/pytensorf.py#L147. With the current code, what do you mean by doing this lazily?
@ricardoV94 This is already in https://github.com/pymc-devs/pymc/blob/main/pymc/pytensorf.py#L147. With the current code, what do you mean by doing this lazily?
That it shouldn't fail if pandas is not installed. Maybe it's actually better to leave this in PyMC, since there is no perfect mapping from pandas to pytensor objects