Skip to content

Commit

Permalink
Apply ruff to jupyter notebooks (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnothman committed Dec 28, 2023
1 parent 9a00998 commit 8984102
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
65 changes: 44 additions & 21 deletions doc/formats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
],
"source": [
"from upsetplot import generate_counts\n",
"\n",
"example_counts = generate_counts()\n",
"example_counts"
]
Expand Down Expand Up @@ -137,6 +138,7 @@
],
"source": [
"from upsetplot import UpSet\n",
"\n",
"ax_dict = UpSet(example_counts).plot()"
]
},
Expand Down Expand Up @@ -182,6 +184,7 @@
],
"source": [
"from upsetplot import generate_samples\n",
"\n",
"example_values = generate_samples().value\n",
"example_values"
]
Expand Down Expand Up @@ -218,7 +221,8 @@
],
"source": [
"from upsetplot import UpSet\n",
"ax_dict = UpSet(example_values, subset_size='count').plot()"
"\n",
"ax_dict = UpSet(example_values, subset_size=\"count\").plot()"
]
},
{
Expand Down Expand Up @@ -253,7 +257,8 @@
],
"source": [
"from upsetplot import UpSet\n",
"ax_dict = UpSet(example_values, subset_size='sum', show_counts=True).plot()"
"\n",
"ax_dict = UpSet(example_values, subset_size=\"sum\", show_counts=True).plot()"
]
},
{
Expand Down Expand Up @@ -365,6 +370,7 @@
],
"source": [
"from upsetplot import generate_samples\n",
"\n",
"example_samples_df = generate_samples()\n",
"example_samples_df.head()"
]
Expand Down Expand Up @@ -401,7 +407,8 @@
],
"source": [
"from upsetplot import UpSet\n",
"ax_dict = UpSet(example_samples_df, subset_size='count').plot()"
"\n",
"ax_dict = UpSet(example_samples_df, subset_size=\"count\").plot()"
]
},
{
Expand Down Expand Up @@ -436,7 +443,8 @@
],
"source": [
"from upsetplot import UpSet\n",
"ax_dict = UpSet(example_samples_df, sum_over='index', subset_size='sum').plot()"
"\n",
"ax_dict = UpSet(example_samples_df, sum_over=\"index\", subset_size=\"sum\").plot()"
]
},
{
Expand Down Expand Up @@ -479,9 +487,9 @@
}
],
"source": [
"mammals = ['Cat', 'Dog', 'Horse', 'Sheep', 'Pig', 'Cattle', 'Rhinoceros', 'Moose']\n",
"herbivores = ['Horse', 'Sheep', 'Cattle', 'Moose', 'Rhinoceros']\n",
"domesticated = ['Dog', 'Chicken', 'Horse', 'Sheep', 'Pig', 'Cattle', 'Duck']\n",
"mammals = [\"Cat\", \"Dog\", \"Horse\", \"Sheep\", \"Pig\", \"Cattle\", \"Rhinoceros\", \"Moose\"]\n",
"herbivores = [\"Horse\", \"Sheep\", \"Cattle\", \"Moose\", \"Rhinoceros\"]\n",
"domesticated = [\"Dog\", \"Chicken\", \"Horse\", \"Sheep\", \"Pig\", \"Cattle\", \"Duck\"]\n",
"(mammals, herbivores, domesticated)"
]
},
Expand Down Expand Up @@ -611,7 +619,10 @@
],
"source": [
"from upsetplot import from_contents\n",
"animals = from_contents({'mammal': mammals, 'herbivore': herbivores, 'domesticated': domesticated})\n",
"\n",
"animals = from_contents(\n",
" {\"mammal\": mammals, \"herbivore\": herbivores, \"domesticated\": domesticated}\n",
")\n",
"animals"
]
},
Expand Down Expand Up @@ -647,7 +658,8 @@
],
"source": [
"from upsetplot import UpSet\n",
"ax_dict = UpSet(animals, subset_size='count').plot()"
"\n",
"ax_dict = UpSet(animals, subset_size=\"count\").plot()"
]
},
{
Expand Down Expand Up @@ -706,7 +718,9 @@
"}\n",
"\n",
"# Turn this into a list of lists:\n",
"animal_membership_lists = [categories.split(\",\") for categories in animal_memberships.values()]\n",
"animal_membership_lists = [\n",
" categories.split(\",\") for categories in animal_memberships.values()\n",
"]\n",
"\n",
"animals = from_memberships(animal_membership_lists)\n",
"animals"
Expand Down Expand Up @@ -744,7 +758,8 @@
],
"source": [
"from upsetplot import UpSet\n",
"ax_dict = UpSet(animals, subset_size='count').plot()"
"\n",
"ax_dict = UpSet(animals, subset_size=\"count\").plot()"
]
},
{
Expand Down Expand Up @@ -924,7 +939,9 @@
"source": [
"import pandas as pd\n",
"\n",
"movies = pd.read_csv(\"https://raw.githubusercontent.com/peetck/IMDB-Top1000-Movies/master/IMDB-Movie-Data.csv\")\n",
"movies = pd.read_csv(\n",
" \"https://raw.githubusercontent.com/peetck/IMDB-Top1000-Movies/master/IMDB-Movie-Data.csv\"\n",
")\n",
"movies.head()"
]
},
Expand Down Expand Up @@ -1582,7 +1599,7 @@
}
],
"source": [
"movies_by_genre = from_memberships(movies.Genre.str.split(','), data=movies)\n",
"movies_by_genre = from_memberships(movies.Genre.str.split(\",\"), data=movies)\n",
"movies_by_genre"
]
},
Expand Down Expand Up @@ -2043,9 +2060,9 @@
}
],
"source": [
"genre_indicators = pd.DataFrame([{cat: True\n",
" for cat in cats}\n",
" for cats in movies.Genre.str.split(',').values]).fillna(False)\n",
"genre_indicators = pd.DataFrame(\n",
" [{cat: True for cat in cats} for cats in movies.Genre.str.split(\",\").values]\n",
").fillna(False)\n",
"genre_indicators"
]
},
Expand All @@ -2061,6 +2078,7 @@
"outputs": [],
"source": [
"from upsetplot import from_indicators\n",
"\n",
"# this produces the same result as from_memberships above\n",
"movies_by_genre = from_indicators(genre_indicators, data=movies)"
]
Expand Down Expand Up @@ -2522,8 +2540,11 @@
}
],
"source": [
"UpSet(from_indicators([\"Drama\", \"Action\", \"Comedy\", \"Adventure\"],\n",
" data=movies_with_indicators))"
"UpSet(\n",
" from_indicators(\n",
" [\"Drama\", \"Action\", \"Comedy\", \"Adventure\"], data=movies_with_indicators\n",
" )\n",
")"
]
},
{
Expand Down Expand Up @@ -2568,9 +2589,11 @@
}
],
"source": [
"UpSet(from_indicators(lambda df: df.select_dtypes(bool),\n",
" data=movies_with_indicators),\n",
" min_subset_size=15, show_counts=True)"
"UpSet(\n",
" from_indicators(lambda df: df.select_dtypes(bool), data=movies_with_indicators),\n",
" min_subset_size=15,\n",
" show_counts=True,\n",
")"
]
}
],
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tool.ruff]
extend-include = ["*.ipynb"]

0 comments on commit 8984102

Please sign in to comment.