Skip to content
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

PandasCursor incorrectly converts some strings as nulls #118

Open
EdwardJRoss opened this issue Feb 2, 2020 · 2 comments
Open

PandasCursor incorrectly converts some strings as nulls #118

EdwardJRoss opened this issue Feb 2, 2020 · 2 comments

Comments

@EdwardJRoss
Copy link

With pyathena 1.10.0 and pandas 1.0.0:

import pyathena
from pyathena.pandas_cursor import PandasCursor

con = pyathena.connect()

query = "select * from (values ('', 'a'), ('N/A', 'a'), ('NULL', 'a'), (NULL, 'a'))"

print(con.cursor().execute(query).fetchall())
print(con.cursor(PandasCursor).execute(query).fetchall())

Expected output:

[('', 'a'), ('N/A', 'a'), ('NULL', 'a'), (None, 'a')]
[('', 'a'), ('N/A', 'a'), ('NULL', 'a'), (nan, 'a')]

Actual output:

[('', 'a'), ('N/A', 'a'), ('NULL', 'a'), (None, 'a')]
[(nan, 'a'), (nan, 'a'), (nan, 'a'), (nan, 'a')]

Underlying reason: The csv file on AWS that PandasCursor uses looks like this

"_col0","_col1"
"","a"
"N/A","a"
"NULL","a"
,"a"

in https://github.com/laughingman7743/PyAthena/blob/master/pyathena/result_set.py#L445 the call to read_csv should has at least something like na_values=[''] and keep_default_na=False.

The problem is how to get pandas read_csv to treat a quoted empty string as the empty string, and an unquoted empty string as a null (in my opinion "quoting=1" (ALL) should do it, but it doesn't).

@laughingman7743
Copy link
Owner

I checked it in the following branch, but I can't judge NULL and empty string well. 😢
#120
I want to know a good way to handle these well. 😭

@acpguedes
Copy link

I got the opposite error.
Some Nulls are converting to empty string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants