Skip to content

Commit 93a217d

Browse files
committed
add types in frames
1 parent 30a8b8c commit 93a217d

File tree

8 files changed

+1960
-1832
lines changed

8 files changed

+1960
-1832
lines changed

coverage.txt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
platform darwin -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0
33
rootdir: /Users/johnmount/Documents/work/wvpy/pkg
44
plugins: anyio-3.5.0, cov-3.0.0
5-
collected 18 items
5+
collected 19 items
66

77
tests/test_cross_plan1.py . [ 5%]
8-
tests/test_cross_predict.py .. [ 16%]
9-
tests/test_deviance_calc.py . [ 22%]
10-
tests/test_eval_fn_pre_row.py . [ 27%]
11-
tests/test_match_auc.py . [ 33%]
12-
tests/test_nb_fns.py ... [ 50%]
13-
tests/test_onehot.py .. [ 61%]
14-
tests/test_perm_score_vars.py . [ 66%]
15-
tests/test_plots.py . [ 72%]
16-
tests/test_se.py . [ 77%]
17-
tests/test_search_grid.py .. [ 88%]
18-
tests/test_stats1.py . [ 94%]
19-
tests/test_threshold_stats.py . [100%]
8+
tests/test_cross_predict.py .. [ 15%]
9+
tests/test_deviance_calc.py . [ 21%]
10+
tests/test_eval_fn_pre_row.py . [ 26%]
11+
tests/test_match_auc.py . [ 31%]
12+
tests/test_nb_fns.py ... [ 47%]
13+
tests/test_onehot.py .. [ 57%]
14+
tests/test_perm_score_vars.py . [ 63%]
15+
tests/test_plots.py . [ 68%]
16+
tests/test_se.py . [ 73%]
17+
tests/test_search_grid.py .. [ 84%]
18+
tests/test_stats1.py . [ 89%]
19+
tests/test_threshold_stats.py . [ 94%]
20+
tests/test_typs_in_frame.py . [100%]
2021

2122
=============================== warnings summary ===============================
2223
../../../../opt/anaconda3/envs/research_env/lib/python3.9/site-packages/seaborn/rcmod.py:82
@@ -36,8 +37,8 @@ wvpy/__init__.py 3 0 100%
3637
wvpy/jtools.py 136 34 75%
3738
wvpy/pysheet.py 33 33 0%
3839
wvpy/render_workbook.py 29 29 0%
39-
wvpy/util.py 316 7 98%
40+
wvpy/util.py 321 7 98%
4041
---------------------------------------------
41-
TOTAL 517 103 80%
42+
TOTAL 522 103 80%
4243

43-
======================= 18 passed, 2 warnings in 15.55s ========================
44+
======================= 19 passed, 2 warnings in 17.22s ========================

pkg/build/lib/wvpy/util.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Utility functions for teaching data science.
33
"""
44

5-
from typing import Iterable, List, Tuple
5+
from typing import Dict, Iterable, List, Tuple
66

77
import re
88
import os
@@ -20,6 +20,25 @@
2020
from data_algebra.cdata import RecordMap, RecordSpecification
2121

2222

23+
def types_in_frame(d: pandas.DataFrame) -> Dict[str, List[type]]:
24+
"""
25+
Report what type as seen as values in a Pandas data frame.
26+
27+
:param d: Pandas data frame to inspect, not altered.
28+
:return: dictionary mapping column names to order lists of types found in column.
29+
"""
30+
assert isinstance(d, pandas.DataFrame)
31+
type_dict_map = {
32+
col_name: {str(type(v)): type(v) for v in d[col_name]}
33+
for col_name in d.columns
34+
}
35+
type_dict = {
36+
col_name: [type_set[k] for k in sorted(list(type_set.keys()))]
37+
for col_name, type_set in type_dict_map.items()
38+
}
39+
return type_dict
40+
41+
2342
# noinspection PyPep8Naming
2443
def cross_predict_model(
2544
fitter, X: pandas.DataFrame, y: pandas.Series, plan: List
215 Bytes
Binary file not shown.

pkg/dist/wvpy-0.3.0.tar.gz

212 Bytes
Binary file not shown.

pkg/docs/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/docs/wvpy/util.html

Lines changed: 1883 additions & 1813 deletions
Large diffs are not rendered by default.

pkg/tests/test_typs_in_frame.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
import pandas as pd
3+
from wvpy.util import types_in_frame
4+
5+
6+
def test_types_in_frame():
7+
d = pd.DataFrame({
8+
'x': [1, 2],
9+
'y': ['a', 'b'],
10+
'z': ['a', 1],
11+
})
12+
found = types_in_frame(d)
13+
expect = {
14+
'x': [int],
15+
'y': [str],
16+
'z': [int, str],
17+
}
18+
assert found == expect
19+

pkg/wvpy/util.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Utility functions for teaching data science.
33
"""
44

5-
from typing import Iterable, List, Tuple
5+
from typing import Dict, Iterable, List, Tuple
66

77
import re
88
import os
@@ -20,6 +20,25 @@
2020
from data_algebra.cdata import RecordMap, RecordSpecification
2121

2222

23+
def types_in_frame(d: pandas.DataFrame) -> Dict[str, List[type]]:
24+
"""
25+
Report what type as seen as values in a Pandas data frame.
26+
27+
:param d: Pandas data frame to inspect, not altered.
28+
:return: dictionary mapping column names to order lists of types found in column.
29+
"""
30+
assert isinstance(d, pandas.DataFrame)
31+
type_dict_map = {
32+
col_name: {str(type(v)): type(v) for v in d[col_name]}
33+
for col_name in d.columns
34+
}
35+
type_dict = {
36+
col_name: [type_set[k] for k in sorted(list(type_set.keys()))]
37+
for col_name, type_set in type_dict_map.items()
38+
}
39+
return type_dict
40+
41+
2342
# noinspection PyPep8Naming
2443
def cross_predict_model(
2544
fitter, X: pandas.DataFrame, y: pandas.Series, plan: List

0 commit comments

Comments
 (0)