Skip to content

Commit 3337d79

Browse files
committed
Fix ImportError handling for tfs package in write_tbt function
1 parent f8278de commit 3337d79

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

turn_by_turn/madng.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ def write_tbt(output_path: str | Path, tbt_data: TbtData) -> None:
182182
Raises:
183183
ImportError: If the ``tfs-pandas`` package is not installed.
184184
"""
185-
if not tfs:
185+
try:
186+
import tfs
187+
except ImportError as e:
186188
raise ImportError(
187189
"The 'tfs' package is required to write MAD-NG TFS files. Install it with: pip install 'turn_by_turn[madng]'"
188-
)
190+
) from e
189191

190192
planes = [plane.lower() for plane in TransverseData.fieldnames()] # x, y
191193
plane_dfs = {plane: [] for plane in planes}

0 commit comments

Comments
 (0)