Hi, I ran into problems while trying to use Symbols as columns for a 
pandas.DataFrame *.
This is probably not relevant to SymPy development itself, but rather just 
use.
This seems to be a problem with both frameworks treating callable() objects 
specially:

>>> import pandas as pd
>>> from sympy.abc import x, y

>>> gg = pd.DataFrame([[1,2],[3,3],[4,5]], columns=[x,y])

>>> print(gg[[x]]) # works fine, but returns a DataFrame
   x
0  1
1  3
2  4
>>> print(gg[x])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\pandas\core\frame.py", line 1941, in __getitem__
    key = com._apply_if_callable(key, self)
  File "...\pandas\core\common.py", line 441, in _apply_if_callable
    return maybe_callable(obj, **kwargs)
  File "...sympy\core\symbol.py", line 158, in __call__
    return Function(self.name)(*args)
  File "...\sympy\core\function.py", line 761, in __new__
    obj = super(AppliedUndef, cls).__new__(cls, *args, **options)
  File "...\sympy\core\function.py", line 431, in __new__
    pr = max(cls._should_evalf(a) for a in result.args)
  File "...\sympy\core\function.py", line 431, in <genexpr>
    pr = max(cls._should_evalf(a) for a in result.args)
  File "...\sympy\core\function.py", line 449, in _should_evalf
    if arg.is_Float:
  File "...\pandas\core\generic.py", line 3081, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'is_Float'

The way to get a pd.Series would be:
>>> gg[[x]].iloc[:,0] # super uncomfortable...
0    1
1    3
2    4
Name: x, dtype: int64


Is there any reasonable way this interaction could be worked around? It 
seems like a problem on the Pandas end, or maybe even designed 
functionality, since functions work the same way (but fail faster):

>>> fg = pd.DataFrame([[1,2],[3,3],[4,5]], columns=[f,g])
>>> fg[[f]]
   <function f at 0x000000000F79BEB8>
0                                   1
1                                   3
2                                   4
>>> fg[f]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...\pandas\core\frame.py", line 1941, in __getitem__
    key = com._apply_if_callable(key, self)
  File "...\pandas\core\common.py", line 441, in _apply_if_callable
    return maybe_callable(obj, **kwargs)
TypeError: f() takes no arguments (1 given)

But is there any way I can check whether the inputs are Symbols and 
"freeze" them so that they become uncallable? Maybe some other workaround? 
Thanks in advance.



* Why am I doing this? Partially due to curiosity, and partially because my 
users might end up doing the same. It turns out that using Symbols as 
variable placeholders in a data science workflow might be useful.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/1f26bab1-a623-4054-b392-c1e78f0ac9a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to