Skip to content

Commit 8d8f6b7

Browse files
PkchaPkcha
authored andcommitted
feat: initial release
1 parent 27a314b commit 8d8f6b7

3 files changed

Lines changed: 69 additions & 64 deletions

File tree

Lines changed: 60 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,60 @@
1-
"""
2-
Auxiliary handler methods for data summary extraction
3-
"""
4-
from typing import Any, Callable, Dict, List, Sequence
5-
6-
import networkx as nx
7-
from visions import VisionsTypeset
8-
9-
10-
def compose(functions: Sequence[Callable]) -> Callable:
11-
"""
12-
Compose a sequence of functions.
13-
14-
:param functions: sequence of functions
15-
:return: combined function applying all functions in order.
16-
"""
17-
18-
def composed_function(*args) -> List[Any]:
19-
result = args # Start with the input arguments
20-
for func in functions:
21-
result = func(*result) if isinstance(result, tuple) else func(result)
22-
return result # type: ignore
23-
24-
return composed_function # type: ignore
25-
26-
27-
class Handler:
28-
"""A generic handler
29-
30-
Allows any custom mapping between data types and functions
31-
"""
32-
33-
def __init__(
34-
self,
35-
mapping: Dict[str, List[Callable]],
36-
typeset: VisionsTypeset,
37-
*args,
38-
**kwargs
39-
):
40-
self.mapping = mapping
41-
self.typeset = typeset
42-
self._complete_dag()
43-
44-
def _complete_dag(self) -> None:
45-
for from_type, to_type in nx.topological_sort(
46-
nx.line_graph(self.typeset.base_graph)
47-
):
48-
self.mapping[str(to_type)] = (
49-
self.mapping[str(from_type)] + self.mapping[str(to_type)]
50-
)
51-
52-
def handle(self, dtype: str, *args, **kwargs) -> dict:
53-
"""
54-
Returns:
55-
object: a tuple containing the config, the dataset series and the summary extracted
56-
"""
57-
funcs = self.mapping.get(dtype, [])
58-
op = compose(funcs)
59-
summary = op(*args)[-1]
60-
return summary
61-
62-
63-
1+
"""
2+
Auxiliary handler methods for data summary extraction
3+
"""
4+
from typing import Any, Callable, Dict, List, Sequence
5+
6+
import networkx as nx
7+
from visions import VisionsTypeset
8+
9+
10+
def compose(functions: Sequence[Callable]) -> Callable:
11+
"""
12+
Compose a sequence of functions.
13+
14+
:param functions: sequence of functions
15+
:return: combined function applying all functions in order.
16+
"""
17+
18+
def composed_function(*args) -> List[Any]:
19+
result = args # Start with the input arguments
20+
for func in functions:
21+
result = func(*result) if isinstance(result, tuple) else func(result)
22+
return result # type: ignore
23+
24+
return composed_function # type: ignore
25+
26+
27+
class Handler:
28+
"""A generic handler
29+
30+
Allows any custom mapping between data types and functions
31+
"""
32+
33+
def __init__(
34+
self,
35+
mapping: Dict[str, List[Callable]],
36+
typeset: VisionsTypeset,
37+
*args,
38+
**kwargs
39+
):
40+
self.mapping = mapping
41+
self.typeset = typeset
42+
self._complete_dag()
43+
44+
def _complete_dag(self) -> None:
45+
for from_type, to_type in nx.topological_sort(
46+
nx.line_graph(self.typeset.base_graph)
47+
):
48+
self.mapping[str(to_type)] = (
49+
self.mapping[str(from_type)] + self.mapping[str(to_type)]
50+
)
51+
52+
def handle(self, dtype: str, *args, **kwargs) -> dict:
53+
"""
54+
Returns:
55+
object: a tuple containing the config, the dataset series and the summary extracted
56+
"""
57+
funcs = self.mapping.get(dtype, [])
58+
op = compose(funcs)
59+
summary = op(*args)[-1]
60+
return summary

src/ydata_profiling/report/structure/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44

55
def get_render_map() -> Dict[str, Callable]:
6+
"""Get the mapping of variable types to their render functions.
7+
8+
This function was moved from model.handler to report.structure to eliminate
9+
the reverse dependency from model layer to report layer.
10+
11+
Returns:
12+
Dictionary mapping type names to render functions.
13+
"""
614
import ydata_profiling.report.structure.variables as render_algorithms
715

816
render_map = {

src/ydata_profiling/utils/backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
File with a function to check the backend being used
2+
Backend detection utilities for pandas and spark.
33
"""
44
import importlib
55

0 commit comments

Comments
 (0)