17
17
18
18
import numpy as np
19
19
from pygmt .clib import Session
20
- from pygmt .exceptions import GMTError , GMTInvalidInput
20
+ from pygmt .exceptions import GMTInvalidInput
21
21
from pygmt .helpers import launch_external_viewer , unique_name
22
22
23
23
@@ -331,11 +331,12 @@ def show(
331
331
match method :
332
332
case "notebook" :
333
333
if not _HAS_IPYTHON :
334
- raise GMTError (
334
+ msg = (
335
335
"Notebook display is selected, but IPython is not available. "
336
336
"Make sure you have IPython installed, "
337
337
"or run the script in a Jupyter notebook."
338
338
)
339
+ raise ImportError (msg )
339
340
png = self ._preview (
340
341
fmt = "png" , dpi = dpi , anti_alias = True , as_bytes = True , ** kwargs
341
342
)
@@ -344,14 +345,15 @@ def show(
344
345
pdf = self ._preview (
345
346
fmt = "pdf" , dpi = dpi , anti_alias = False , as_bytes = False , ** kwargs
346
347
)
347
- launch_external_viewer (pdf , waiting = waiting ) # type: ignore[arg-type]
348
+ launch_external_viewer (pdf , waiting = waiting )
348
349
case "none" :
349
350
pass # Do nothing
350
351
case _:
351
- raise GMTInvalidInput (
352
- f"Invalid display method '{ method } '. Valid values are 'external', "
353
- "'notebook', 'none' or None."
352
+ msg = (
353
+ f"Invalid display method '{ method } '. "
354
+ "Valid values are 'external', 'notebook', 'none' or None."
354
355
)
356
+ raise GMTInvalidInput (msg )
355
357
356
358
def _preview (self , fmt : str , dpi : int , as_bytes : bool = False , ** kwargs ):
357
359
"""
@@ -400,7 +402,7 @@ def _repr_html_(self):
400
402
html = '<img src="data:image/png;base64,{image}" width="{width}px">'
401
403
return html .format (image = base64_png .decode ("utf-8" ), width = 500 )
402
404
403
- from pygmt .src import ( # type: ignore [misc]
405
+ from pygmt .src import ( # type: ignore[misc]
404
406
basemap ,
405
407
coast ,
406
408
colorbar ,
0 commit comments