HyukjinKwon commented on code in PR #38621: URL: https://github.com/apache/spark/pull/38621#discussion_r1020208301
########## python/pyspark/sql/connect/dataframe.py: ########## @@ -388,8 +388,55 @@ def sample( session=self._session, ) - def show(self, n: int, truncate: Optional[Union[bool, int]], vertical: Optional[bool]) -> None: - ... + def _show_string( + self, n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False + ) -> str: + if not isinstance(n, int) or isinstance(n, bool): + raise TypeError("Parameter 'n' (number of rows) must be an int") + if not isinstance(vertical, bool): + raise TypeError("Parameter 'vertical' must be a bool") + + _truncate: int = -1 + if isinstance(truncate, bool) and truncate: + _truncate = 20 + else: + try: + _truncate = int(truncate) + except ValueError: + raise TypeError( + "Parameter 'truncate={}' should be either bool or int.".format(truncate) + ) + + pdf = DataFrame.withPlan( + plan.ShowString(child=self._plan, numRows=n, truncate=_truncate, vertical=vertical), + session=self._session, + ).toPandas() + assert pdf is not None + return pdf.iloc[0, 0] + + def show(self, n: int = 20, truncate: Union[bool, int] = True, vertical: bool = False) -> None: + """ + Prints the first ``n`` rows to the console. + + .. versionadded:: 3.4.0 + + Parameters + ---------- + n : int, optional + Number of rows to show. + truncate : bool or int, optional + If set to ``True``, truncate strings longer than 20 chars by default. + If set to a number greater than one, truncates long strings to length ``truncate`` + and align cells right. + vertical : bool, optional + If set to ``True``, print output rows vertically (one line + per column value). + + Returns + ------- + None Review Comment: I think we can just remove ```suggestion ``` -- 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