-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added filter to locate columns (#1115)
* feat: added filter to locate columns * Update .pre-commit-config.yaml * Apply suggestions from code review Co-authored-by: Aarni Koskela <[email protected]> * feat: added support for variable search in ipywidgets * fix: variables not being filtered according to dropdown * fix: variables not being filtered according to dropdown * fix: fixed order of sections Co-authored-by: Aarni Koskela <[email protected]>
- Loading branch information
1 parent
ebbc089
commit 4919cd3
Showing
10 changed files
with
124 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Any, Callable | ||
|
||
from pandas_profiling.report.presentation.core.item_renderer import ItemRenderer | ||
from pandas_profiling.report.presentation.core.container import Container | ||
from pandas_profiling.report.presentation.core.renderable import Renderable | ||
|
||
class Dropdown(ItemRenderer): | ||
def __init__(self, name: str, id: str, items: list, item: Container, anchor_id: str, **kwargs): | ||
super().__init__("dropdown", {"name": name, "id": id, "items": items, "item": item, "anchor_id": anchor_id,}, **kwargs) | ||
|
||
def __repr__(self) -> str: | ||
return "Dropdown" | ||
|
||
def render(self) -> Any: | ||
raise NotImplementedError() | ||
|
||
@classmethod | ||
def convert_to_class(cls, obj: Renderable, flv: Callable) -> None: | ||
obj.__class__ = cls | ||
if "item" in obj.content: | ||
flv(obj.content["item"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/pandas_profiling/report/presentation/flavours/html/dropdown.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pandas_profiling.report.presentation.core import Dropdown | ||
from pandas_profiling.report.presentation.flavours.html import templates | ||
|
||
|
||
class HTMLDropdown(Dropdown): | ||
def render(self) -> str: | ||
return templates.template("dropdown.html").render(**self.content) |
8 changes: 8 additions & 0 deletions
8
src/pandas_profiling/report/presentation/flavours/html/templates/dropdown.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<select name="{{ name }}" id="{{ id }}"> | ||
<option value="">Select Columns</option> | ||
{% for item in items %} | ||
<option value="{{ item }}">{{ item }}</option> | ||
{% endfor %} | ||
</select> | ||
|
||
{{ item.render() }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/pandas_profiling/report/presentation/flavours/widget/dropdown.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from ipywidgets import widgets | ||
|
||
from pandas_profiling.report.presentation.core import Dropdown | ||
|
||
|
||
class WidgetDropdown(Dropdown): | ||
def render(self) -> widgets.VBox: | ||
dropdown = widgets.Dropdown( | ||
options=self.content["items"], | ||
description=self.content["name"] | ||
) | ||
titles = [] | ||
item = self.content["item"].content["items"] | ||
for i in item: | ||
titles.append(i.name) | ||
item = self.content["item"].render() | ||
def change_view(widg: dict) -> None: | ||
if(dropdown.value == ""): | ||
item.selected_index = None | ||
else: | ||
for i in range(len(titles)): | ||
if(titles[i] == dropdown.value): | ||
item.selected_index = i | ||
break | ||
|
||
dropdown.observe(change_view, names=["value"]) | ||
|
||
if(self.content["item"] != None): | ||
return widgets.VBox([dropdown, item]) | ||
else: | ||
return widgets.Vbox([dropdown]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters