Databricks Certified Machine Learning Associate · Free Practice Question Medium
Question 4
Which of the following options in Pandas API on Spark sets the limit for a shortcut and computes a specified number of rows using its schema?
-
A
display.max_rows
-
B
compute.ops_on_diff_frames
-
C
compute.shortcut_limit
-
D
compute.default_index_type
Reveal correct answer
Correct answer: C
Explanation
Correct Answer:compute.shortcut_limit
Explanation:
Why This Is Correct?
compute.shortcut_limitin pandas API on Spark determines how many rows are computed locally (on the driver) to infer schema or perform quick checks, avoiding full distributed computation.Default: Typically 1000 rows.
Use Case: Speeds up operations like
df.head()or schema inference by sampling.
Example:
- import pyspark.pandas as ps
- ps.set_option("compute.shortcut_limit", 500) # Only compute 500 rows for schema checks
Key Impact:
Performance: Reduces latency for metadata operations.
Trade-off: Too low → schema inference errors; too high → slower driver ops.
Why Other Options Are Incorrect?
display.max_rows:Controls how many rows print/show (e.g.,
df.display()).
compute.ops_on_diff_frames:Allows operations between unrelated DataFrames (unrelated to sampling).
compute.default_index_type:Sets index type (e.g., "distributed" vs. "sequence").
Key Takeaway:
For efficient schema checks in pandas-on-Spark:
Adjust
compute.shortcut_limitbased on data size.Use
df.spark.schema()for full schema without sampling.
Pro Tip: Increase this value if you encounter schema mismatches in large DataFrames.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
