ueshin commented on code in PR #38223: URL: https://github.com/apache/spark/pull/38223#discussion_r1013488987
########## python/pyspark/worker.py: ########## @@ -188,22 +241,7 @@ def wrapped(key_series, value_series): elif len(argspec.args) == 2: key = tuple(s[0] for s in key_series) result = f(key, pd.concat(value_series, axis=1)) - - if not isinstance(result, pd.DataFrame): - raise TypeError( - "Return type of the user-defined function should be " - "pandas.DataFrame, but is {}".format(type(result)) - ) - # the number of columns of result have to match the return type - # but it is fine for result to have no columns at all if it is empty - if not ( - len(result.columns) == len(return_type) or len(result.columns) == 0 and result.empty - ): - raise RuntimeError( - "Number of columns of the returned pandas.DataFrame " - "doesn't match specified schema. " - "Expected: {} Actual: {}".format(len(return_type), len(result.columns)) - ) + verify_pandas_result(result, return_type, assign_cols_by_name(runner_conf)) Review Comment: ditto. ########## python/pyspark/worker.py: ########## @@ -159,27 +226,13 @@ def wrapped(left_key_series, left_value_series, right_key_series, right_value_se key_series = left_key_series if not left_df.empty else right_key_series key = tuple(s[0] for s in key_series) result = f(key, left_df, right_df) - if not isinstance(result, pd.DataFrame): - raise TypeError( - "Return type of the user-defined function should be " - "pandas.DataFrame, but is {}".format(type(result)) - ) - # the number of columns of result have to match the return type - # but it is fine for result to have no columns at all if it is empty - if not ( - len(result.columns) == len(return_type) or len(result.columns) == 0 and result.empty - ): - raise RuntimeError( - "Number of columns of the returned pandas.DataFrame " - "doesn't match specified schema. " - "Expected: {} Actual: {}".format(len(return_type), len(result.columns)) - ) + verify_pandas_result(result, return_type, assign_cols_by_name(runner_conf)) Review Comment: I guess we can call `assign_cols_by_name(runner_conf)` outside of `wrapped`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org