Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to provide more helpful error if load_dataset is given a DataFrame #2604

Merged
merged 1 commit into from
Jul 24, 2021

Conversation

mwaskom
Copy link
Owner

@mwaskom mwaskom commented Jun 22, 2021

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).

@mwaskom mwaskom added this to the v0.12.0 milestone Jun 22, 2021
@mwaskom mwaskom force-pushed the load_dataset_error branch from 9ba43f1 to 19cacbc Compare June 22, 2021 19:00
@codecov
Copy link

codecov bot commented Jun 22, 2021

Codecov Report

Merging #2604 (19cacbc) into master (445a54a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2604   +/-   ##
=======================================
  Coverage   97.44%   97.45%           
=======================================
  Files          17       17           
  Lines        6350     6353    +3     
=======================================
+ Hits         6188     6191    +3     
  Misses        162      162           
Impacted Files Coverage Δ
seaborn/utils.py 94.61% <100.00%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 445a54a...19cacbc. Read the comment docs.

@mwaskom mwaskom merged commit 9c3dba6 into master Jul 24, 2021
@mwaskom mwaskom deleted the load_dataset_error branch July 24, 2021 19:02
@mwaskom mwaskom modified the milestones: v0.12.0, v0.11.2 Aug 6, 2021
mwaskom added a commit that referenced this pull request Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant