Skip to content

Commit

Permalink
Add coerce_float option to as_pandas (#291)
Browse files Browse the repository at this point in the history
Pass the coerce_float option to the DataFrame.from_records call.
  • Loading branch information
guillemborrell authored and timarmstrong committed Feb 27, 2019
1 parent 84da2b8 commit 15cf338
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions impala/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_logger_and_init_null(logger_name):
log = get_logger_and_init_null(__name__)


def as_pandas(cursor):
def as_pandas(cursor, coerce_float=False):
"""Return a pandas `DataFrame` out of an impyla cursor.
This will pull the entire result set into memory. For richer pandas-like
Expand All @@ -49,14 +49,19 @@ def as_pandas(cursor):
----------
cursor : `HiveServer2Cursor`
The cursor object that has a result set waiting to be fetched.
coerce_float : bool, optional
Attempt to convert values of non-string, non-numeric objects to floating
point.
Returns
-------
DataFrame
"""
from pandas import DataFrame # pylint: disable=import-error
names = [metadata[0] for metadata in cursor.description]
return DataFrame.from_records(cursor.fetchall(), columns=names)
return DataFrame.from_records(cursor.fetchall(), columns=names,
coerce_float=coerce_float)


def _random_id(prefix='', length=8):
Expand Down

0 comments on commit 15cf338

Please sign in to comment.