grundprinzip commented on code in PR #47153:
URL: https://github.com/apache/spark/pull/47153#discussion_r1675673046


##########
python/pyspark/errors/utils.py:
##########
@@ -257,3 +248,41 @@ def with_origin_to_class(cls: Type[T]) -> Type[T]:
             ):
                 setattr(cls, name, _with_origin(method))
     return cls
+
+
+def call_site_stack(depth: int = 10) -> List[inspect.FrameInfo]:
+    """
+    Capture the call site stack and filter out all stack frames that are not 
user code.
+
+    This function will return the call stack above all PySpark code and 
IPython code. Usually
+    the first frame will be the place where the user code reached the PySpark 
API.
+
+    If SPARK_TESTING is set in the environment, all frames will be returned.
+
+    Parameters
+    ----------
+    depth : int
+        How many stack frames to select
+
+    """
+
+    # Filtering out PySpark code and keeping user code only
+    pyspark_root = os.path.dirname(pyspark.__file__)
+    stack = [
+        frame_info
+        for frame_info in inspect.stack()
+        if pyspark_root not in frame_info.filename or "SPARK_TESTING" in 
os.environ
+    ]
+
+    selected_frames = stack[:depth]
+
+    # We try import here since IPython is not a required dependency
+    try:
+        import IPython
+
+        ipy_root = IPython.__file__

Review Comment:
   Thanks for fixing that!



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

Reply via email to