itholic commented on a change in pull request #34931:
URL: https://github.com/apache/spark/pull/34931#discussion_r774317596
##########
File path: python/pyspark/pandas/tests/test_dataframe.py
##########
@@ -5779,14 +5779,116 @@ def test_astype(self):
psdf.astype({"c": float})
def test_describe(self):
- psdf = self.psdf
+ pdf, psdf = self.df_pair
+
+ # numeric columns
+ self.assert_eq(psdf.describe(), pdf.describe())
+ psdf.a += psdf.a
+ pdf.a += pdf.a
+ self.assert_eq(psdf.describe(), pdf.describe())
+
+ # string columns
+ psdf = ps.DataFrame({"A": ["a", "b", "b", "c"], "B": ["d", "e", "f",
"f"]})
+ pdf = psdf.to_pandas()
+ self.assert_eq(psdf.describe(), pdf.describe().astype(str))
+ psdf.A += psdf.A
+ pdf.A += pdf.A
+ self.assert_eq(psdf.describe(), pdf.describe().astype(str))
+
+ # timestamp columns
+ psdf = ps.DataFrame(
+ {
+ "A": [
+ pd.Timestamp("2020-10-20"),
+ pd.Timestamp("2021-06-02"),
+ pd.Timestamp("2021-06-02"),
+ pd.Timestamp("2022-07-11"),
+ ],
+ "B": [
+ pd.Timestamp("2021-11-20"),
+ pd.Timestamp("2023-06-02"),
+ pd.Timestamp("2026-07-11"),
+ pd.Timestamp("2026-07-11"),
+ ],
+ }
+ )
+ pdf = psdf.to_pandas()
+ # NOTE: Set `datetime_is_numeric=True` for pandas:
+ # FutureWarning: Treating datetime data as categorical rather than
numeric in `.describe` is deprecated
+ # and will be removed in a future version of pandas. Specify
`datetime_is_numeric=True` to silence this
+ # warning and adopt the future behavior now.
+ # NOTE: Compare the result except percentiles, since we use
approximate percentile
+ # so the result is different from pandas.
+ self.assert_eq(
+ psdf.describe().loc[["count", "mean", "min", "max"]],
+ pdf.describe(datetime_is_numeric=True).astype(str).loc[["count",
"mean", "min", "max"]],
+ )
+
+ # String & timestamp columns
+ psdf = ps.DataFrame(
+ {
+ "A": ["a", "b", "b", "c"],
+ "B": [
+ pd.Timestamp("2021-11-20"),
+ pd.Timestamp("2023-06-02"),
+ pd.Timestamp("2026-07-11"),
+ pd.Timestamp("2026-07-11"),
+ ],
+ }
+ )
+ pdf = psdf.to_pandas()
+ self.assert_eq(
+ psdf.describe().loc[["count", "mean", "min", "max"]],
+ pdf.describe(datetime_is_numeric=True).astype(str).loc[["count",
"mean", "min", "max"]],
+ )
+ psdf.A += psdf.A
+ pdf.A += pdf.A
+ self.assert_eq(
+ psdf.describe().loc[["count", "mean", "min", "max"]],
+ pdf.describe(datetime_is_numeric=True).astype(str).loc[["count",
"mean", "min", "max"]],
+ )
+
+ # Numeric & timestamp columns
+ psdf = ps.DataFrame(
+ {
+ "A": [1, 2, 2, 3],
+ "B": [
+ pd.Timestamp("2021-11-20"),
+ pd.Timestamp("2023-06-02"),
+ pd.Timestamp("2026-07-11"),
+ pd.Timestamp("2026-07-11"),
+ ],
+ }
+ )
+ pdf = psdf.to_pandas()
+ pandas_result = pdf.describe(datetime_is_numeric=True)
+ pandas_result.B = pandas_result.B.astype(str)
+ self.assert_eq(
+ psdf.describe().loc[["count", "mean", "min", "max"]],
+ pandas_result.loc[["count", "mean", "min", "max"]],
+ )
+ psdf.A += psdf.A
+ pdf.A += pdf.A
+ pandas_result = pdf.describe(datetime_is_numeric=True)
+ pandas_result.B = pandas_result.B.astype(str)
+ self.assert_eq(
+ psdf.describe().loc[["count", "mean", "min", "max"]],
+ pandas_result.loc[["count", "mean", "min", "max"]],
+ )
+
+ # Empty DataFrame
+ psdf = ps.DataFrame(columns=["A", "B"])
Review comment:
Sounds good, just added!
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]