Reraise errors in this block to show metadata inference failure. Parameters ---------- funcname : str, optional If provided, will be added to the error message to indicate the name of the method that failed.
(funcname=None, udf=False)
| 137 | |
| 138 | @contextmanager |
| 139 | def raise_on_meta_error(funcname=None, udf=False): |
| 140 | """Reraise errors in this block to show metadata inference failure. |
| 141 | |
| 142 | Parameters |
| 143 | ---------- |
| 144 | funcname : str, optional |
| 145 | If provided, will be added to the error message to indicate the |
| 146 | name of the method that failed. |
| 147 | """ |
| 148 | try: |
| 149 | yield |
| 150 | except Exception as e: |
| 151 | exc_type, exc_value, exc_traceback = sys.exc_info() |
| 152 | tb = "".join(traceback.format_tb(exc_traceback)) |
| 153 | msg = "Metadata inference failed{0}.\n\n" |
| 154 | if udf: |
| 155 | msg += ( |
| 156 | "You have supplied a custom function and Dask is unable to \n" |
| 157 | "determine the type of output that that function returns. \n\n" |
| 158 | "To resolve this please provide a meta= keyword.\n" |
| 159 | "The docstring of the Dask function you ran should have more information.\n\n" |
| 160 | ) |
| 161 | msg += ( |
| 162 | "Original error is below:\n" |
| 163 | "------------------------\n" |
| 164 | "{1}\n\n" |
| 165 | "Traceback:\n" |
| 166 | "---------\n" |
| 167 | "{2}" |
| 168 | ) |
| 169 | msg = msg.format(f" in `{funcname}`" if funcname else "", repr(e), tb) |
| 170 | raise ValueError(msg) from e |
| 171 | |
| 172 | |
| 173 | UNKNOWN_CATEGORIES = "__UNKNOWN_CATEGORIES__" |