BUG/FIX: Fix dtype inference issue in query
closes #8568 

merged via https://github.com/pydata/pandas/commit/3788c65735445eb2142d83fdd7e7633c7f6a7b43
 FYI, parser=python doesn't like the not syntax for some reason (I just added a test).
