You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "itholic (via GitHub)" <gi...@apache.org> on 2024/06/18 08:24:22 UTC
[PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
itholic opened a new pull request, #47009:
URL: https://github.com/apache/spark/pull/47009
### What changes were proposed in this pull request?
This PR proposes to display correct call site information from IPython Notebook.
### Why are the changes needed?
We added `DataFrameQueryContext` for PySpark error message from https://github.com/apache/spark/pull/45377, but it does not working very well from IPython Notebook.
### Does this PR introduce _any_ user-facing change?
No API changes, but the user-facing error message from IPython Notebook will be improved:
**Before**
<img width="1124" alt="Screenshot 2024-06-18 at 5 15 56 PM" src="https://github.com/apache/spark/assets/44108233/3e3aee2c-5bb0-4858-b392-e845b7280d31">
**After**
<img width="1121" alt="Screenshot 2024-06-18 at 5 14 36 PM" src="https://github.com/apache/spark/assets/44108233/2560726a-bb6f-4f7b-8604-49ef9e4339b8">
### How was this patch tested?
Manually tested with IPython Notebook.
### 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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #47009:
URL: https://github.com/apache/spark/pull/47009#discussion_r1645237250
##########
python/pyspark/errors/utils.py:
##########
@@ -165,8 +165,37 @@ def _capture_call_site(spark_session: "SparkSession", depth: int) -> str:
in the user code that led to the error.
"""
stack = list(reversed(inspect.stack()))
+ ipython = None
+
+ # We try import here since IPython is not a required dependency
+ try:
+ from IPython import get_ipython
+
+ ipython = get_ipython()
+ except ImportError:
+ pass
+
+ if ipython:
+ import pyspark
+
+ # 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
+ ]
+
+ depth = int(
Review Comment:
Can we respect the argument `depth` if set?
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on code in PR #47009:
URL: https://github.com/apache/spark/pull/47009#discussion_r1645239980
##########
python/pyspark/errors/utils.py:
##########
@@ -165,8 +165,37 @@ def _capture_call_site(spark_session: "SparkSession", depth: int) -> str:
in the user code that led to the error.
"""
stack = list(reversed(inspect.stack()))
+ ipython = None
+
+ # We try import here since IPython is not a required dependency
+ try:
+ from IPython import get_ipython
+
+ ipython = get_ipython()
+ except ImportError:
+ pass
+
+ if ipython:
+ import pyspark
+
+ # 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
+ ]
+
+ depth = int(
Review Comment:
I think maybe we already respect `depth` below by `selected_frames = stack[:depth]` ??
##########
python/pyspark/errors/utils.py:
##########
@@ -165,8 +165,37 @@ def _capture_call_site(spark_session: "SparkSession", depth: int) -> str:
in the user code that led to the error.
"""
stack = list(reversed(inspect.stack()))
+ ipython = None
+
+ # We try import here since IPython is not a required dependency
+ try:
+ from IPython import get_ipython
+
+ ipython = get_ipython()
+ except ImportError:
+ pass
+
+ if ipython:
+ import pyspark
+
+ # 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
+ ]
+
+ depth = int(
Review Comment:
Oh, didn't realize it. Let me address
##########
python/pyspark/errors/utils.py:
##########
@@ -165,8 +165,37 @@ def _capture_call_site(spark_session: "SparkSession", depth: int) -> str:
in the user code that led to the error.
"""
stack = list(reversed(inspect.stack()))
+ ipython = None
+
+ # We try import here since IPython is not a required dependency
+ try:
+ from IPython import get_ipython
+
+ ipython = get_ipython()
+ except ImportError:
+ pass
+
+ if ipython:
+ import pyspark
+
+ # 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
+ ]
+
+ depth = int(
Review Comment:
adjusted!
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon closed pull request #47009: [SPARK-48650][PYTHON] Display correct call site from IPython Notebook
URL: https://github.com/apache/spark/pull/47009
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on PR #47009:
URL: https://github.com/apache/spark/pull/47009#issuecomment-2177264313
Now we use the cell number instead of file name for better debuggability.
Updated before/after in PR description. cc @allisonwang-db FYI
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on code in PR #47009:
URL: https://github.com/apache/spark/pull/47009#discussion_r1645242054
##########
python/pyspark/errors/utils.py:
##########
@@ -165,8 +165,37 @@ def _capture_call_site(spark_session: "SparkSession", depth: int) -> str:
in the user code that led to the error.
"""
stack = list(reversed(inspect.stack()))
+ ipython = None
+
+ # We try import here since IPython is not a required dependency
+ try:
+ from IPython import get_ipython
+
+ ipython = get_ipython()
+ except ImportError:
+ pass
+
+ if ipython:
+ import pyspark
+
+ # 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
+ ]
+
+ depth = int(
Review Comment:
now this functions take a parameter called `depth` :-).
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "HyukjinKwon (via GitHub)" <gi...@apache.org>.
HyukjinKwon commented on PR #47009:
URL: https://github.com/apache/spark/pull/47009#issuecomment-2185652546
Merged to master.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-48650][PYTHON] Display correct call site from IPython Notebook [spark]
Posted by "itholic (via GitHub)" <gi...@apache.org>.
itholic commented on PR #47009:
URL: https://github.com/apache/spark/pull/47009#issuecomment-2177246711
@allisonwang-db Actually that is a good point. Let me try highlighting and providing more useful debugging information from error message.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org