pytensor icon indicating copy to clipboard operation
pytensor copied to clipboard

Move pandas converters to pytensor

Open ferrine opened this issue 2 years ago • 1 comments

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

ferrine avatar Nov 30 '22 06:11 ferrine

Is there a way to do this lazily?

ricardoV94 avatar Dec 07 '23 12:12 ricardoV94

@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?

HangenYuu avatar Jul 22 '24 03:07 HangenYuu

@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

ricardoV94 avatar Jul 22 '24 15:07 ricardoV94