druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

[fix] Ensuring export_pandas returns a pandas.DataFrame #189

Closed john-bodley closed 4 years ago

john-bodley commented 4 years ago

Per the docstring the export_pandas method returns an object of type pandas.DataFrame however the return type was also None if no results were defined.

You can't simply check a pandas.DataFrame for truthiness and thus the following isn't valid,

df = client.export_pandas()

if df:
     ...

when you're returning a mix of None and pandas.DataFrame. Currently you would need to be the somewhat verbose:

df = client.export_pandas()

if df is not None and not df.empty():
     ...

This PR ensures the method always returns a pandas.DataFrame regardless of the results, i.e., one can simply use:

df = client.export_pandas()

if not df.empty():
     ...

to: @betodealmeida @mistercrunch