Open tobgu opened 7 years ago
Is there a reason you are not using the idiomatic assignment?
In [5]: df['c'] = 'foo'
In [6]: df
Out[6]:
a b c
0 1 2 foo
1 3 4 foo
I suppose this could be allowed. Note that there is NO benefit to actually doing it in .eval
AT ALL. (unlike numeric operations which are accelerated using numexpr
).
@chris-b1 IIRC you worked on some of this.
The example above was just a minimal one to show the problem. The actual code that fails for me takes an expression on another form and transforms it into opertations that are applied to a DataFrame. For this it was very convenient to use eval since it is very straight forward to produce an expression that can be evaluated using eval() given the input. I could produce the same operations in python code (the idiomatic way) it would just require some more code on my side.
This has worked fine for me in python 2.7 but now I'm looking into migrating the application to python 3.6 and this error seemed like a regression to me. That's why I reported it (+ to get some input on alternative ways to achieve the same purpose).
I can confirm that this is working in python 2.7, but not in python 3. So in any case, this inconsistency is a bug, and it should probably just work for both?
@tobgu And thanks for reporting!
Code Sample, a copy-pastable example if possible
Problem description
It does not seem possible to assign string values to columns under Python 3.6 (probably under all Python 3.X versions but I've only tried it with 3.6).
On python 2.7.12 the above works fine.
Expected Output
A data frame with all rows in column c set to the string 'foo'.
Output of
pd.show_versions()