-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
whitespaces in column name handled differently than input to eval/query #28893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think you're right, notice that in line |
I had an initial look at this. The expression parser seems to assume that column names would not be differentiated based on the number of whitespaces in them according to how it's written here: pandas/pandas/core/computation/expr.py Lines 60 to 64 in d8f9be7
The tokenize module generates tokens and excludes the whitespaces. I would've further looked into this, but this is literally my first go at debugging issues in open-source projects so just here to observe and learn first 😅. I just left this as a reference for someone to have a look into this. Moreover |
Hello, if the maintainers are going to accept my PR this is going to be fixed in #28215. |
Fixed in #28215 |
Code Sample
Problem description
When using backticks in the input to
DataFrame.query
orDataFrame.eval
, it seems that the number of whitespaces betweenCol
and1
, is mapped into:Col_1_BACKTICK_QUOTED_STRING
, regardless of how many whitespaces there are betweenCol
and1
.Having 2 whitespaces when defining the column name in the DataFrame, it seems that the column name is defined as:
Col__1_BACKTICK_QUOTED_STRING
.With 10 whitespaces:
Col__________1_BACKTICK_QUOTED_STRING
, and so forth.This makes the number of whitespaces in the column name important, as column name will be based on the amount of them. However, the number of whitespaces in the input to
DataFrame.query
orDataFrame.eval
does not seem to have any affect, and will always have one underscore, and not match the column name if it has more than one whitespace.Expected Output
The expected output would be to have the column name and the input to
query
oreval
transformed with the same function, having a one to one mapping between whitespaces and underscores when definding the variable. i.e.2 whitespaces:
Col__1_BACKTICK_QUOTED_STRING
.10 whitespaces:
Col__________1_BACKTICK_QUOTED_STRING
.Output of
pd.show_versions()
pandas : 0.25.1
numpy : 1.17.2
pytz : 2019.3
dateutil : 2.8.0
pip : 19.2.3
setuptools : 41.4.0
Cython : None
pytest : 5.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : 2.7.0
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.15.0
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : None
tables : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
The text was updated successfully, but these errors were encountered: