Skip to content

Commit 249743f

Browse files
committed
Fix Athena NaN values when ctas_approach is False. #351
1 parent 420b4d2 commit 249743f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

awswrangler/athena/_read.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _fetch_csv_result(
265265
converters=query_metadata.converters,
266266
quoting=csv.QUOTE_ALL,
267267
keep_default_na=False,
268-
na_values=[""],
268+
na_values=["", "NaN"],
269269
chunksize=_chunksize,
270270
skip_blank_lines=False,
271271
use_threads=False,

tests/test_athena.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import boto3
55
import pandas as pd
66
import pytest
7+
import numpy as np
78

89
import awswrangler as wr
910

@@ -772,3 +773,17 @@ def test_parse_describe_table():
772773
def test_describe_table(path, glue_database, glue_table):
773774
wr.catalog.create_parquet_table(database=glue_database, table=glue_table, path=path, columns_types={"c0": "int"})
774775
assert wr.athena.describe_table(database=glue_database, table=glue_table).shape == (1, 4)
776+
777+
778+
@pytest.mark.parametrize("ctas_approach", [False, True])
779+
def test_athena_nan_inf(glue_database, ctas_approach):
780+
sql = "SELECT nan() AS nan, infinity() as inf, -infinity() as inf_n, 1.2 as regular"
781+
df = wr.athena.read_sql_query(sql, glue_database, ctas_approach)
782+
print(df)
783+
print(df.dtypes)
784+
assert df.shape == (1, 4)
785+
assert df.dtypes.to_list() == ["float64", "float64", "float64", "float64"]
786+
assert np.isnan(df.nan.iloc[0])
787+
assert df.inf.iloc[0] == np.PINF
788+
assert df.inf_n.iloc[0] == np.NINF
789+
assert df.regular.iloc[0] == 1.2

0 commit comments

Comments
 (0)