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

   ### What changes were proposed in this pull request?
   
   Fixes usage logger attachment to handle static methods properly.
   
   ### Why are the changes needed?
   
   The usage logger attachment logic has an issue when handling static methods.
   
   For example,
   
   ```
   $ PYSPARK_PANDAS_USAGE_LOGGER=pyspark.pandas.usage_logging.usage_logger 
./bin/pyspark
   ```
   ```py
   >>> import pyspark.pandas as ps
   >>> psdf = ps.DataFrame({"a": [1,2,3], "b": [4,5,6]})
   >>> psdf.from_records([(1, 2), (3, 4)])
   A function `DataFrame.from_records(data, index, exclude, columns, 
coerce_float, nrows)` was failed after 2007.430 ms: 0
   Traceback (most recent call last):
   ...
   ```
   
   without usage logger:
   
   ```py
   >>> import pyspark.pandas as ps
   >>> psdf = ps.DataFrame({"a": [1,2,3], "b": [4,5,6]})
   >>> psdf.from_records([(1, 2), (3, 4)])
      0  1
   0  1  2
   1  3  4
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, for a user attaches the usage logger, static methods will work as 
static methods.
   
   ### How was this patch tested?
   
   Manually tested.
   
   ```py
   >>> import pyspark.pandas as ps
   >>> import logging
   >>> import sys
   >>> root = logging.getLogger()
   >>> root.setLevel(logging.INFO)
   >>> handler = logging.StreamHandler(sys.stdout)
   >>> handler.setLevel(logging.INFO)
   >>>
   >>> formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - 
%(message)s')
   >>> handler.setFormatter(formatter)
   >>> root.addHandler(handler)
   
   >>> psdf = ps.DataFrame({"a": [1,2,3], "b": [4,5,6]})
   2022-04-12 14:43:52,254 - pyspark.pandas.usage_logger - INFO - A function 
`DataFrame.__init__(self, data, index, columns, dtype, copy)` was successfully 
finished after 2714.896 ms.
   >>> psdf.from_records([(1, 2), (3, 4)])
   2022-04-12 14:43:59,765 - pyspark.pandas.usage_logger - INFO - A function 
`DataFrame.from_records(data, index, exclude, columns, coerce_float, nrows)` 
was successfully finished after 51.105 ms.
   2022-04-12 14:44:01,371 - pyspark.pandas.usage_logger - INFO - A function 
`DataFrame.__repr__(self)` was successfully finished after 1605.759 ms.
      0  1
   0  1  2
   1  3  4
   
   >>> ps.DataFrame.from_records([(1, 2), (3, 4)])
   2022-04-12 14:44:25,301 - pyspark.pandas.usage_logger - INFO - A function 
`DataFrame.from_records(data, index, exclude, columns, coerce_float, nrows)` 
was successfully finished after 43.446 ms.
   2022-04-12 14:44:25,493 - pyspark.pandas.usage_logger - INFO - A function 
`DataFrame.__repr__(self)` was successfully finished after 192.053 ms.
      0  1
   0  1  2
   1  3  4
   ```


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