Try to provide more helpful error if load_dataset is given a DataFrame #2604
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This should help reduce confusion following a relatively common beginner mistake. The current result is useless for solving the problem:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-245-abe567917c1d> in <module> ----> 1 sns.load_dataset(tips) ~/code/seaborn/seaborn/utils.py in load_dataset(name, cache, data_home, **kws) 479 os.path.basename(full_path)) 480 if not os.path.exists(cache_path): --> 481 if name not in get_dataset_names(): 482 raise ValueError(f"'{name}' is not one of the example datasets.") 483 urlretrieve(full_path, cache_path) ~/miniconda3/envs/seaborn-py38-latest/lib/python3.8/site-packages/pandas/core/generic.py in __nonzero__(self) 1440 @final 1441 def __nonzero__(self): -> 1442 raise ValueError( 1443 f"The truth value of a {type(self).__name__} is ambiguous. " 1444 "Use a.empty, a.bool(), a.item(), a.any() or a.all()." ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().Now we have
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-d18ae242c087> in <module> ----> 1 sns.load_dataset(pd.DataFrame([])) ~/code/seaborn/seaborn/utils.py in load_dataset(name, cache, data_home, **kws) 480 "it is not necessary to use this function before plotting." 481 ) --> 482 raise TypeError(err) 483 484 url = f"https://raw.githubusercontent.com/mwaskom/seaborn-data/master/{name}.csv" TypeError: This function accepts only strings (the name of an example dataset). You passed a pandas DataFrame. If you have your own dataset, it is not necessary to use this function before plotting.Note that this does involve a change in Exception type (but the new type is the correct one).