zhengruifeng opened a new pull request, #44869:
URL: https://github.com/apache/spark/pull/44869

   ### What changes were proposed in this pull request?
   1, Introduce a basic fallback mechanism for frame methods, with a new option 
`compute.pandas_fallback` default false;
   2, implement `Frame.asfreq` and `Frame.asof`
   
   ### Why are the changes needed?
   for pandas parity
   
   ### Does this PR introduce _any_ user-facing change?
   yes
   
   ```
   In [1]: import pyspark.pandas as ps
      ...: import pandas as pd
      ...: 
      ...: index = pd.date_range('1/1/2000', periods=4, freq='min')
      ...: series = pd.Series([0.0, None, 2.0, 3.0], index=index)
      ...: pdf = pd.DataFrame({'s': series})
      ...: psdf = ps.from_pandas(pdf)
   
   In [2]: psdf.asfreq(freq='30s')
   ---------------------------------------------------------------------------
   PandasNotImplementedError                 Traceback (most recent call last)
   Cell In[2], line 1
   ----> 1 psdf.asfreq(freq='30s')
   
   File ~/Dev/spark/python/pyspark/pandas/missing/__init__.py:23, in 
unsupported_function.<locals>.unsupported_function(*args, **kwargs)
        22 def unsupported_function(*args, **kwargs):
   ---> 23     raise PandasNotImplementedError(
        24         class_name=class_name, method_name=method_name, reason=reason
        25     )
   
   PandasNotImplementedError: The method `pd.DataFrame.asfreq()` is not 
implemented yet.
   
   In [3]: ps.set_option("compute.pandas_fallback", True)
   
   In [4]: psdf.asfreq(freq='30s')
   /Users/ruifeng.zheng/Dev/spark/python/pyspark/pandas/utils.py:1015: 
PandasAPIOnSparkAdviceWarning: `asfreq` is executed in fallback mode. It loads 
partial data into the driver's memory to infer the schema, and loads all data 
into one executor's memory to compute. It should only be used if the pandas 
DataFrame is expected to be small.
     warnings.warn(message, PandasAPIOnSparkAdviceWarning)
   /Users/ruifeng.zheng/Dev/spark/python/pyspark/pandas/utils.py:1015: 
PandasAPIOnSparkAdviceWarning: If the type hints is not specified for 
`groupby.apply`, it is expensive to infer the data type internally.
     warnings.warn(message, PandasAPIOnSparkAdviceWarning)
   Out[4]:                                                                      
   
                          s
   2000-01-01 00:00:00  0.0
   2000-01-01 00:00:30  NaN
   2000-01-01 00:01:00  NaN
   2000-01-01 00:01:30  NaN
   2000-01-01 00:02:00  2.0
   2000-01-01 00:02:30  NaN
   2000-01-01 00:03:00  3.0
   ```
   
   
   ### How was this patch tested?
   added ut
   
   ### Was this patch authored or co-authored using generative AI tooling?
   no
   


-- 
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]

Reply via email to