Improve exception type.

ImportError isn't really appropriate when there's no import involved.
This commit is contained in:
Aymeric Augustin
2019-12-23 21:23:08 +01:00
parent 4c09a96096
commit c8b0c1e551
5 changed files with 7 additions and 7 deletions

View File

@@ -324,7 +324,7 @@ def squad_convert_examples_to_features(
del new_features
if return_dataset == "pt":
if not is_torch_available():
raise ImportError("Pytorch must be installed to return a pytorch dataset.")
raise RuntimeError("PyTorch must be installed to return a PyTorch dataset.")
# Convert to Tensors and build dataset
all_input_ids = torch.tensor([f.input_ids for f in features], dtype=torch.long)
@@ -354,7 +354,7 @@ def squad_convert_examples_to_features(
return features, dataset
elif return_dataset == "tf":
if not is_tf_available():
raise ImportError("TensorFlow must be installed to return a TensorFlow dataset.")
raise RuntimeError("TensorFlow must be installed to return a TensorFlow dataset.")
def gen():
for ex in features:

View File

@@ -294,7 +294,7 @@ class SingleSentenceClassificationProcessor(DataProcessor):
return features
elif return_tensors == "tf":
if not is_tf_available():
raise ImportError("return_tensors set to 'tf' but TensorFlow 2.0 can't be imported")
raise RuntimeError("return_tensors set to 'tf' but TensorFlow 2.0 can't be imported")
import tensorflow as tf
def gen():
@@ -309,7 +309,7 @@ class SingleSentenceClassificationProcessor(DataProcessor):
return dataset
elif return_tensors == "pt":
if not is_torch_available():
raise ImportError("return_tensors set to 'pt' but PyTorch can't be imported")
raise RuntimeError("return_tensors set to 'pt' but PyTorch can't be imported")
import torch
from torch.utils.data import TensorDataset