toolsos 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- toolsos/geo.py +1 -1
- toolsos/huisstijl/graphs/bargraph.py +14 -11
- toolsos/huisstijl/maps/choropleth.py +22 -8
- toolsos/huisstijl/tables/table_helpers.py +1 -1
- toolsos/huisstijl/tables/tables.py +67 -10
- {toolsos-0.3.1.dist-info → toolsos-0.3.3.dist-info}/METADATA +3 -2
- {toolsos-0.3.1.dist-info → toolsos-0.3.3.dist-info}/RECORD +9 -9
- {toolsos-0.3.1.dist-info → toolsos-0.3.3.dist-info}/WHEEL +1 -1
- {toolsos-0.3.1.dist-info → toolsos-0.3.3.dist-info}/top_level.txt +0 -0
toolsos/geo.py
CHANGED
|
@@ -105,7 +105,7 @@ def get_geo_name_code(level: str, year: int, mra: bool = False) -> dict[str, str
|
|
|
105
105
|
Returns:
|
|
106
106
|
dict[str, str]: _description_
|
|
107
107
|
"""
|
|
108
|
-
json = get_geo_json(level=level, year=year)
|
|
108
|
+
json = get_geo_json(level=level, year=year, mra=mra)
|
|
109
109
|
name_code = extract_name_code_table(json)
|
|
110
110
|
return name_code
|
|
111
111
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
1
3
|
import plotly.express as px
|
|
2
4
|
|
|
3
5
|
from .styler import BaseStyle
|
|
@@ -9,13 +11,13 @@ def bar(
|
|
|
9
11
|
data,
|
|
10
12
|
x: str,
|
|
11
13
|
y: str,
|
|
12
|
-
color: str = None,
|
|
13
|
-
color_discrete_sequence: list = None,
|
|
14
|
-
orientation: str = None,
|
|
15
|
-
barmode=None,
|
|
16
|
-
width=750,
|
|
17
|
-
height=490,
|
|
18
|
-
font="Amsterdam Sans",
|
|
14
|
+
color: Optional[str] = None,
|
|
15
|
+
color_discrete_sequence: Optional[list[str]] = None,
|
|
16
|
+
orientation: Optional[str] = None,
|
|
17
|
+
barmode: Optional[str] = None,
|
|
18
|
+
width: int = 750,
|
|
19
|
+
height: int = 490,
|
|
20
|
+
font: str = "Amsterdam Sans",
|
|
19
21
|
**kwargs,
|
|
20
22
|
):
|
|
21
23
|
fig = px.bar(
|
|
@@ -42,10 +44,10 @@ def stacked_single(
|
|
|
42
44
|
data,
|
|
43
45
|
x: str,
|
|
44
46
|
y: str,
|
|
45
|
-
color: str = None,
|
|
46
|
-
color_discrete_sequence: list = None,
|
|
47
|
-
orientation="v",
|
|
48
|
-
font="Amsterdam Sans",
|
|
47
|
+
color: Optional[str] = None,
|
|
48
|
+
color_discrete_sequence: Optional[list[str]] = None,
|
|
49
|
+
orientation: str = "v",
|
|
50
|
+
font: str = "Amsterdam Sans",
|
|
49
51
|
**kwargs,
|
|
50
52
|
):
|
|
51
53
|
fig = bar(
|
|
@@ -133,6 +135,7 @@ def single(
|
|
|
133
135
|
y=y,
|
|
134
136
|
color_discrete_sequence=color_discrete_sequence,
|
|
135
137
|
orientation=orientation,
|
|
138
|
+
barmode="relative",
|
|
136
139
|
font=font,
|
|
137
140
|
**kwargs,
|
|
138
141
|
)
|
|
@@ -11,12 +11,12 @@ def plot_choropleth(
|
|
|
11
11
|
gdf: gpd.GeoDataFrame,
|
|
12
12
|
column: str,
|
|
13
13
|
colors: Iterable[str],
|
|
14
|
-
column_label: Optional[
|
|
15
|
-
column_label_kwargs: Any = None,
|
|
14
|
+
column_label: Optional[bool] = False,
|
|
15
|
+
column_label_kwargs: Optional[dict[Any]] = None,
|
|
16
16
|
legend_title: Optional[str] = None,
|
|
17
17
|
edgecolor: str = "grey",
|
|
18
18
|
figsize: tuple[int, int] = (10, 8),
|
|
19
|
-
bbox_to_anchor: tuple[
|
|
19
|
+
bbox_to_anchor: tuple[float, int] = (-0.05, 0),
|
|
20
20
|
ax: Optional[axis.Axis] = None,
|
|
21
21
|
):
|
|
22
22
|
_ax = ax
|
|
@@ -34,7 +34,17 @@ def plot_choropleth(
|
|
|
34
34
|
linewidth=0.2,
|
|
35
35
|
)
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
try:
|
|
38
|
+
labels = gdf[column].cat.categories
|
|
39
|
+
except AttributeError:
|
|
40
|
+
plt.close("all")
|
|
41
|
+
raise Exception(
|
|
42
|
+
"""
|
|
43
|
+
The column provided should be an categorical column. Use pd.Categorical(df[column])
|
|
44
|
+
to turn the column into a Categorical column. If the order of the legend is important
|
|
45
|
+
provide the levels and set ordered=True
|
|
46
|
+
"""
|
|
47
|
+
)
|
|
38
48
|
|
|
39
49
|
if not column_label_kwargs:
|
|
40
50
|
column_label_kwargs = {}
|
|
@@ -54,10 +64,7 @@ def plot_choropleth(
|
|
|
54
64
|
)
|
|
55
65
|
|
|
56
66
|
# Create custom legend using the 'colors' and 'labels' variables, with a grey border
|
|
57
|
-
legend_elements =
|
|
58
|
-
Patch(facecolor=color, label=label, edgecolor="#b0b0b0")
|
|
59
|
-
for color, label in zip(colors, labels)
|
|
60
|
-
]
|
|
67
|
+
legend_elements = _build_legend(colors, labels)
|
|
61
68
|
|
|
62
69
|
# Move the legend to the bottom left outside the plot
|
|
63
70
|
ax.legend(
|
|
@@ -76,3 +83,10 @@ def plot_choropleth(
|
|
|
76
83
|
|
|
77
84
|
if not _ax:
|
|
78
85
|
return fig, ax
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _build_legend(colors, labels):
|
|
89
|
+
return [
|
|
90
|
+
Patch(facecolor=color, label=label, edgecolor="#b0b0b0")
|
|
91
|
+
for color, label in zip(colors, labels)
|
|
92
|
+
]
|
|
@@ -10,7 +10,7 @@ def remove_underscores_from_columns(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def get_excel_files_from_folder(folder: str) -> list[str]:
|
|
13
|
-
return [str(f.resolve()) for f in Path(
|
|
13
|
+
return [str(f.resolve()) for f in Path(folder).glob("*") if f.suffix == ".xlsx"]
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def combine_excel_files(out_path: str, files: list[str] = None, overwrite: bool = True):
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import functools
|
|
2
|
-
import json
|
|
3
1
|
import re
|
|
4
|
-
import warnings
|
|
5
2
|
from itertools import groupby
|
|
6
3
|
from typing import Any, Callable, Dict
|
|
7
4
|
|
|
@@ -21,7 +18,6 @@ LOOKUP: dict[str, Callable] = {
|
|
|
21
18
|
"border": Border,
|
|
22
19
|
"protection": Protection,
|
|
23
20
|
"side": Side,
|
|
24
|
-
"border": Border,
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
@@ -79,7 +75,7 @@ def get_max_col_widths(data: pd.DataFrame | np.ndarray) -> list[float]:
|
|
|
79
75
|
return col_widths
|
|
80
76
|
|
|
81
77
|
|
|
82
|
-
def flatten_multiindex_columns(df):
|
|
78
|
+
def flatten_multiindex_columns(df: pd.DataFrame) -> list:
|
|
83
79
|
column_multi = []
|
|
84
80
|
for level in range(df.columns.nlevels):
|
|
85
81
|
column_multi.append(df.columns.get_level_values(level))
|
|
@@ -253,7 +249,6 @@ def set_style_col(
|
|
|
253
249
|
for col_idx in col_idxs:
|
|
254
250
|
for row_idx, _ in enumerate(fmt):
|
|
255
251
|
if row_idx not in exlude_row_ids:
|
|
256
|
-
|
|
257
252
|
update_format(fmt, row_idx, col_idx, mapping)
|
|
258
253
|
|
|
259
254
|
return fmt
|
|
@@ -323,6 +318,8 @@ def cell_formatting(
|
|
|
323
318
|
right_align_ids: int | list | None = None,
|
|
324
319
|
perc_col_ids: int | list | None = None,
|
|
325
320
|
perc_col_format: str | None = None,
|
|
321
|
+
float_col_ids: int | list | None = None,
|
|
322
|
+
float_col_format: str | None = None,
|
|
326
323
|
blue_border_ids: bool | None = None,
|
|
327
324
|
number_format: str | None = None,
|
|
328
325
|
):
|
|
@@ -375,6 +372,13 @@ def cell_formatting(
|
|
|
375
372
|
fmt, perc_col_ids, {"number_format": {"format": perc_col_format}}
|
|
376
373
|
)
|
|
377
374
|
|
|
375
|
+
if float_col_ids:
|
|
376
|
+
if not float_col_format:
|
|
377
|
+
float_col_format = "0.00"
|
|
378
|
+
fmt = set_style_col(
|
|
379
|
+
fmt, float_col_ids, {"number_format": {"format": float_col_format}}
|
|
380
|
+
)
|
|
381
|
+
|
|
378
382
|
if blue_border_ids:
|
|
379
383
|
fmt = set_style_row(fmt, blue_border_ids, STYLES["blue_border_bottom"])
|
|
380
384
|
|
|
@@ -507,6 +511,9 @@ def write_table(
|
|
|
507
511
|
perc_ids: list | None = None,
|
|
508
512
|
perc_pattern: str | None = None,
|
|
509
513
|
perc_col_format: str | None = None,
|
|
514
|
+
float_ids: list | None = None,
|
|
515
|
+
float_pattern: str | None = None,
|
|
516
|
+
float_col_format: str | None = None,
|
|
510
517
|
blue_border: bool | None = True,
|
|
511
518
|
blue_border_row_ids: int | list[int] | None = None,
|
|
512
519
|
number_format: str = "0.0",
|
|
@@ -518,6 +525,39 @@ def write_table(
|
|
|
518
525
|
combine_multiindex: bool | int = False,
|
|
519
526
|
column_names_to_string: bool = True,
|
|
520
527
|
):
|
|
528
|
+
"""_summary_
|
|
529
|
+
|
|
530
|
+
Args:
|
|
531
|
+
data (pd.DataFrame | dict[pd.DataFrame]): dataframe or dicts with dataframes
|
|
532
|
+
file (str): destination file path
|
|
533
|
+
header_row (int, optional): Id of header row. Defaults to 0.
|
|
534
|
+
header_row (int): Set the number of rows to be dark blue (zero-indexed). Defaults to 0 (top row)
|
|
535
|
+
title (str): Set the title above the table. In the case of multiple tables provide a dict in
|
|
536
|
+
which te keys correspond to the sheet name. Defaults to none
|
|
537
|
+
source (str | None, optional): Descriptiopn to be added underneath the table. Defaults to None.
|
|
538
|
+
total_row (bool, optional): Color bottom row blue
|
|
539
|
+
light_blue_row_ids (int | list[int] | None, optional): Row to be formatted light_blue. Defaults to None.
|
|
540
|
+
total_col (bool, optional): Color last column blue.
|
|
541
|
+
right_align_ids (list, optional): The ids of the columns to right align. Defaults to None
|
|
542
|
+
right_align_pattern (str, optional): Pattern of columns to right align. Defaults to None.
|
|
543
|
+
right_align_numeric (bool, optional): Right align numeric columns. Defaults to True.
|
|
544
|
+
left_align_ids (list, optional): The ids of the columns to left align. Defaults to None.
|
|
545
|
+
left_align_pattern (str, optional): Pattern of columns to left align. Defaults to None.
|
|
546
|
+
left_align_string (bool, optional): Left align string columns. Defaults to True.
|
|
547
|
+
perc_ids (list, optional): The ids of the columns to format as percentage. Defaults to None.
|
|
548
|
+
perc_pattern (str, optional): The pattern of columns to format as percentage. Defaults to None.
|
|
549
|
+
perc_col_format (str, optional): The formatting string of percentage columns. Defaults to None.
|
|
550
|
+
blue_border (bool | None, optional): _description_. Defaults to True.
|
|
551
|
+
blue_border_row_ids (int | list[int] | None, optional): _description_. Defaults to None.
|
|
552
|
+
number_format (str, optional): _description_. Defaults to "0.0".
|
|
553
|
+
autofit_columns (str | None, optional): _description_. Defaults to None.
|
|
554
|
+
column_widths (list[int] | None, optional): _description_. Defaults to None.
|
|
555
|
+
min_column_width (int | None, optional): _description_. Defaults to None.
|
|
556
|
+
col_filter (bool, optional): Set filter on columns. Defaults to False.
|
|
557
|
+
style (str, optional): _description_. Defaults to "old".
|
|
558
|
+
combine_multiindex (bool | int, optional): _description_. Defaults to False.
|
|
559
|
+
column_names_to_string (bool, optional): _description_. Defaults to True.
|
|
560
|
+
"""
|
|
521
561
|
wb = Workbook()
|
|
522
562
|
# Empty sheet is created on Workbook creation
|
|
523
563
|
del wb["Sheet"]
|
|
@@ -547,6 +587,9 @@ def write_table(
|
|
|
547
587
|
perc_ids=perc_ids,
|
|
548
588
|
perc_pattern=perc_pattern,
|
|
549
589
|
perc_col_format=perc_col_format,
|
|
590
|
+
float_ids=float_ids,
|
|
591
|
+
float_pattern=float_pattern,
|
|
592
|
+
float_col_format=float_col_format,
|
|
550
593
|
blue_border=blue_border,
|
|
551
594
|
blue_border_row_ids=blue_border_row_ids,
|
|
552
595
|
number_format=number_format,
|
|
@@ -597,6 +640,9 @@ def format_worksheet(
|
|
|
597
640
|
perc_ids: list | None = None,
|
|
598
641
|
perc_pattern: str | None = None,
|
|
599
642
|
perc_col_format: str | None = None,
|
|
643
|
+
float_ids: list | None = None,
|
|
644
|
+
float_pattern: str | None = None,
|
|
645
|
+
float_col_format: str | None = None,
|
|
600
646
|
blue_border: bool | None = True,
|
|
601
647
|
blue_border_row_ids: int | list[int] | None = None,
|
|
602
648
|
number_format: str = "0.0",
|
|
@@ -628,7 +674,7 @@ def format_worksheet(
|
|
|
628
674
|
perc_col_format (str, optional): The formatting string of percentage columns. Defaults to None.
|
|
629
675
|
col_filter (bool, optional): Set filter on columns. Defaults to False.
|
|
630
676
|
"""
|
|
631
|
-
if column_names_to_string
|
|
677
|
+
if column_names_to_string:
|
|
632
678
|
df = cols_to_str(df)
|
|
633
679
|
|
|
634
680
|
arr = df_to_array(df)
|
|
@@ -640,6 +686,7 @@ def format_worksheet(
|
|
|
640
686
|
r_align_ids = []
|
|
641
687
|
l_align_ids = []
|
|
642
688
|
p_ids = []
|
|
689
|
+
f_ids = []
|
|
643
690
|
cells_to_merge = []
|
|
644
691
|
title_tbl = None
|
|
645
692
|
title_src = None
|
|
@@ -681,9 +728,17 @@ def format_worksheet(
|
|
|
681
728
|
p_ids.extend(perc_ids)
|
|
682
729
|
|
|
683
730
|
if perc_pattern:
|
|
684
|
-
|
|
685
|
-
p_ids.extend(
|
|
686
|
-
r_align_ids.extend(
|
|
731
|
+
pr_id = get_cols_id_with_pattern(df, perc_pattern)
|
|
732
|
+
p_ids.extend(pr_id)
|
|
733
|
+
r_align_ids.extend(pr_id)
|
|
734
|
+
|
|
735
|
+
if float_ids:
|
|
736
|
+
f_ids.extend(float_ids)
|
|
737
|
+
|
|
738
|
+
if float_pattern:
|
|
739
|
+
fr_id = get_cols_id_with_pattern(df, float_pattern)
|
|
740
|
+
f_ids.extend(fr_id)
|
|
741
|
+
r_align_ids.extend(fr_id)
|
|
687
742
|
|
|
688
743
|
if total_row:
|
|
689
744
|
light_blue_rows.append(arr.shape[0] - 1)
|
|
@@ -729,6 +784,8 @@ def format_worksheet(
|
|
|
729
784
|
right_align_ids=r_align_ids,
|
|
730
785
|
perc_col_ids=p_ids,
|
|
731
786
|
perc_col_format=perc_col_format,
|
|
787
|
+
float_col_ids=f_ids,
|
|
788
|
+
float_col_format=float_col_format,
|
|
732
789
|
number_format=number_format,
|
|
733
790
|
blue_border_ids=blue_border_ids,
|
|
734
791
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: toolsos
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: OS tools
|
|
5
5
|
Author-email: OS <d.schmitz@amsterdam.nl>
|
|
6
6
|
Keywords: tools,Onderzoek & Statistiek
|
|
@@ -27,6 +27,7 @@ Requires-Dist: pyyaml; extra == "all"
|
|
|
27
27
|
Requires-Dist: requests; extra == "all"
|
|
28
28
|
Requires-Dist: sqlalchemy; extra == "all"
|
|
29
29
|
Requires-Dist: geopandas; extra == "all"
|
|
30
|
+
Requires-Dist: ipykernel; extra == "all"
|
|
30
31
|
|
|
31
32
|
# Tools Onderzoek & Statistiek
|
|
32
33
|
|
|
@@ -2,7 +2,7 @@ toolsos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
2
2
|
toolsos/cbs_tools.py,sha256=361cogk0aIU4D4BKHaa7YSOBh64t5C3zrHlqtWx0iIc,3465
|
|
3
3
|
toolsos/create_tables.py,sha256=43FHK3EERjumBtnGhngIdtthZzcc_Qi37lJ1MgATzBg,908
|
|
4
4
|
toolsos/download.py,sha256=88hehmPL5m5d1nrcJjltuh4xrCItF5EYHaZdHOcSt-g,2652
|
|
5
|
-
toolsos/geo.py,sha256=
|
|
5
|
+
toolsos/geo.py,sha256=nxIU62po7bexK3ZEC8p2ad65jCqKNMowA3CjU3Ad17w,3493
|
|
6
6
|
toolsos/helpers.py,sha256=U4MNRj8pz2iKOTMOzuRg-PdgIBBb21sedWYDWfstvWU,1319
|
|
7
7
|
toolsos/polars_helpers.py,sha256=P3RHLQFeDL7-9U_Q1n4ma_NSkdYAiker4pnc57uluHw,770
|
|
8
8
|
toolsos/database/database_connection.py,sha256=HCP8H_-iE2BOOQDp9v1HOgfUSX45XS-aqw7Nzf8drAU,4359
|
|
@@ -10,18 +10,18 @@ toolsos/database/database_transfer.py,sha256=1ghq5VEtKyOdCKdM45uOyrZSoXMuWsdC35R
|
|
|
10
10
|
toolsos/huisstijl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
toolsos/huisstijl/colors.py,sha256=lSCHCdSjge5cGfLfAObd6mV6TaXq3QGImLOmoGJpGkw,1484
|
|
12
12
|
toolsos/huisstijl/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
toolsos/huisstijl/graphs/bargraph.py,sha256
|
|
13
|
+
toolsos/huisstijl/graphs/bargraph.py,sha256=-NfQ1Eo3SMJb4nAZCVdWSiEHI17SAmOSbyCHfujfKLg,2987
|
|
14
14
|
toolsos/huisstijl/graphs/graph_styles.py,sha256=Z9LLH7j8ODTsYMYK0rslacphuiRDcq5_IpSjEEiK2VY,975
|
|
15
15
|
toolsos/huisstijl/graphs/linegraph.py,sha256=dMUarRe31SXaY78OCXLy-PgnU8LlVJ9KkzKaHhDtuuI,698
|
|
16
16
|
toolsos/huisstijl/graphs/piegraph.py,sha256=aEFiEM-9QuhBOjKHSXVuE5bTh-8uucq4FP6O8Vk1vZI,703
|
|
17
17
|
toolsos/huisstijl/graphs/styler.py,sha256=-uZ7pjY1G39XvmaGHQd31gPRxjxmJGhYZk8xhy2JUWc,6623
|
|
18
18
|
toolsos/huisstijl/maps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
-
toolsos/huisstijl/maps/choropleth.py,sha256=
|
|
19
|
+
toolsos/huisstijl/maps/choropleth.py,sha256=2B2Av5hQXkuFHR-TDcDndSmksji-mIwGoqq_JDMwO6w,2531
|
|
20
20
|
toolsos/huisstijl/tables/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
21
|
-
toolsos/huisstijl/tables/table_helpers.py,sha256=
|
|
21
|
+
toolsos/huisstijl/tables/table_helpers.py,sha256=Q1VuaEHl__K0xFQOeucihN212joTkxhcNbS6wKZaMew,2033
|
|
22
22
|
toolsos/huisstijl/tables/table_styles.py,sha256=oYU6GJcfqlKpZof5PUjPsA7woJ3Tew78CHPyT0_jY6w,1343
|
|
23
|
-
toolsos/huisstijl/tables/tables.py,sha256=
|
|
24
|
-
toolsos-0.3.
|
|
25
|
-
toolsos-0.3.
|
|
26
|
-
toolsos-0.3.
|
|
27
|
-
toolsos-0.3.
|
|
23
|
+
toolsos/huisstijl/tables/tables.py,sha256=Ri08lyz0y9PYdtTpWpVdDAiGlgVYW2JEyawg636cfWQ,28194
|
|
24
|
+
toolsos-0.3.3.dist-info/METADATA,sha256=lqAFIt4-_XNUrHfsgIQSIfC90WdXCZd7V-j9U5y8D0c,2767
|
|
25
|
+
toolsos-0.3.3.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
26
|
+
toolsos-0.3.3.dist-info/top_level.txt,sha256=2ClEjUBbtfDQ8oPwvWRy1Sz2nrkLCXlg0mHaMdCWia0,8
|
|
27
|
+
toolsos-0.3.3.dist-info/RECORD,,
|
|
File without changes
|