-
Notifications
You must be signed in to change notification settings - Fork 14k
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
[fix] Enforce the QueryResult.df to be a pandas.DataFrame object (Phase I) #8935
[fix] Enforce the QueryResult.df to be a pandas.DataFrame object (Phase I) #8935
Conversation
def _add_filter_from_pre_query_data( | ||
self, df: Optional[pd.DataFrame], dimensions, dim_filter | ||
): | ||
def _add_filter_from_pre_query_data(self, df: pd.DataFrame, dimensions, dim_filter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type from client.export_pandas()
is never None
per here.
@@ -439,11 +439,7 @@ def get_df_payload(self, query_obj=None, **kwargs): | |||
and self.status != utils.QueryStatus.FAILED | |||
): | |||
try: | |||
cache_value = dict( | |||
dttm=cached_dttm, | |||
df=df if df is not None else None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
df if df is not None else None
is merely df
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
732f1d1
to
aaba7da
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me. I approve of greater consistency in return values.
@@ -439,11 +439,7 @@ def get_df_payload(self, query_obj=None, **kwargs): | |||
and self.status != utils.QueryStatus.FAILED | |||
): | |||
try: | |||
cache_value = dict( | |||
dttm=cached_dttm, | |||
df=df if df is not None else None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very true.
@@ -1379,7 +1377,7 @@ def query(self, query_obj: Dict) -> QueryResult: | |||
|
|||
if df is None or df.size == 0: | |||
return QueryResult( | |||
df=pd.DataFrame([]), | |||
df=pd.DataFrame(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is equivalent.
@@ -1155,6 +1153,9 @@ def process_data(self, df, aggregate=False): | |||
if fd.get("granularity") == "all": | |||
raise Exception(_("Pick a time granularity for your time series")) | |||
|
|||
if df.empty: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short circuiting as pivot_table
will throw an exception if the pandas.DataFrame
is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -77,6 +77,8 @@ | |||
"size", | |||
] | |||
|
|||
VizData = Optional[Union[List[Any], Dict[Any, Any]]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, we should really leverage alias types more.
@@ -439,11 +439,7 @@ def get_df_payload(self, query_obj=None, **kwargs): | |||
and self.status != utils.QueryStatus.FAILED | |||
): | |||
try: | |||
cache_value = dict( | |||
dttm=cached_dttm, | |||
df=df if df is not None else None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CATEGORY
Choose one
SUMMARY
In the past we have discussed whether we should use an empty
pandas.DataFrame
object orNone
to represent no-data. Previouslydf
attribute of theQueryResult
class could either beNone
or apandas.DataFrame
object and was inconsistency defined, i.e., the Druid native connector used the former whereas the SQL connector used the later. This was problematic as theNone
type wasn't always handled, e.g. here and here would both throw an exception ifdf
wasNone
.This PR ensures that the
df
attribute is always apandas.DataFrame
object which can be empty.Additionally I’ve also added some basic typing to help enforce a non-optional
pandas.DataFrame
and also provided a short circuit when processing of data for theNVD3TimeSeriesViz
class if the data-frame is empty.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
CI.
ADDITIONAL INFORMATION
REVIEWERS
to: @etr2460 @michellethomas @mistercrunch @serenajiang @villebro @willbarrett