toolsos 0.2.1__tar.gz → 0.2.3__tar.gz

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.
Files changed (31) hide show
  1. {toolsos-0.2.1 → toolsos-0.2.3}/PKG-INFO +2 -2
  2. {toolsos-0.2.1 → toolsos-0.2.3}/pyproject.toml +2 -2
  3. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/graphs/linegraph.py +11 -1
  4. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/graphs/piegraph.py +3 -0
  5. toolsos-0.2.3/src/toolsos/huisstijl/tables/table_helpers.py +76 -0
  6. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/tables/tables.py +177 -105
  7. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos.egg-info/PKG-INFO +2 -2
  8. toolsos-0.2.1/src/toolsos/huisstijl/tables/table_helpers.py +0 -6
  9. {toolsos-0.2.1 → toolsos-0.2.3}/README.md +0 -0
  10. {toolsos-0.2.1 → toolsos-0.2.3}/setup.cfg +0 -0
  11. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/__init__.py +0 -0
  12. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/cbs_tools.py +0 -0
  13. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/create_tables.py +0 -0
  14. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/database/database_connection.py +0 -0
  15. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/database/database_transfer.py +0 -0
  16. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/download.py +0 -0
  17. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/geo.py +0 -0
  18. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/helpers.py +0 -0
  19. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/__init__.py +0 -0
  20. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/colors.py +0 -0
  21. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/graphs/__init__.py +0 -0
  22. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/graphs/bargraph.py +0 -0
  23. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/graphs/graph_styles.py +0 -0
  24. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/graphs/styler.py +0 -0
  25. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/tables/__init__.py +0 -0
  26. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/huisstijl/tables/table_styles.py +0 -0
  27. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos/polars_helpers.py +0 -0
  28. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos.egg-info/SOURCES.txt +0 -0
  29. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos.egg-info/dependency_links.txt +0 -0
  30. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos.egg-info/requires.txt +0 -0
  31. {toolsos-0.2.1 → toolsos-0.2.3}/src/toolsos.egg-info/top_level.txt +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: toolsos
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: OS tools
5
5
  Author-email: OS <d.schmitz@amsterdam.nl>
6
6
  Keywords: tools,Onderzoek & Statistiek
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python
9
9
  Classifier: Programming Language :: Python :: 3
10
- Requires-Python: >=3.11
10
+ Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: black; extra == "dev"
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
 
7
7
  [project]
8
8
  name = "toolsos"
9
- version = "0.2.1"
9
+ version = "0.2.3"
10
10
  description = "OS tools"
11
11
  readme = "README.md"
12
12
  authors = [{ name = "OS", email = "d.schmitz@amsterdam.nl" }]
@@ -25,7 +25,7 @@ keywords = ["tools", "Onderzoek & Statistiek"]
25
25
  # use pip install "toolsos[all]" to pip install with al dependencies
26
26
 
27
27
  dependencies = []
28
- requires-python = ">=3.11"
28
+ requires-python = ">=3.10"
29
29
 
30
30
  [project.optional-dependencies]
31
31
  dev = [
@@ -5,7 +5,16 @@ from .styler import BaseStyle
5
5
  basestyle = BaseStyle()
6
6
 
7
7
 
8
- def line(data, x, y, color: None, width=750, height=490, **kwargs):
8
+ def line(
9
+ data,
10
+ x,
11
+ y,
12
+ color: None,
13
+ width=750,
14
+ height=490,
15
+ color_discrete_sequence=None,
16
+ **kwargs,
17
+ ):
9
18
  fig = px.line(
10
19
  data_frame=data,
11
20
  x=x,
@@ -13,6 +22,7 @@ def line(data, x, y, color: None, width=750, height=490, **kwargs):
13
22
  color=color,
14
23
  width=width,
15
24
  height=height,
25
+ color_discrete_sequence=color_discrete_sequence,
16
26
  template=BaseStyle().get_base_template(graph_type="line"),
17
27
  **kwargs,
18
28
  )
@@ -1,4 +1,5 @@
1
1
  import plotly.express as px
2
+
2
3
  from .styler import BaseStyle
3
4
 
4
5
  basestyle = BaseStyle()
@@ -12,6 +13,7 @@ def pie(
12
13
  width=750,
13
14
  height=490,
14
15
  text_format: str = None,
16
+ color_discrete_sequence=None,
15
17
  **kwargs,
16
18
  ):
17
19
  fig = px.pie(
@@ -22,6 +24,7 @@ def pie(
22
24
  height=height,
23
25
  hole=hole,
24
26
  template=BaseStyle().get_base_template(),
27
+ color_discrete_sequence=color_discrete_sequence,
25
28
  **kwargs,
26
29
  )
27
30
 
@@ -0,0 +1,76 @@
1
+ from pathlib import Path
2
+
3
+ import pandas as pd
4
+ import win32com.client as win32
5
+
6
+
7
+ def remove_underscores_from_columns(df: pd.DataFrame) -> pd.DataFrame:
8
+ df.columns = df.columns.str.replace("_", " ")
9
+ return df
10
+
11
+
12
+ def get_excel_files_from_folder(folder: str) -> list[str]:
13
+ return [str(f.resolve()) for f in Path("to_merge").glob("*") if f.suffix == ".xlsx"]
14
+
15
+
16
+ def combine_excel_files(out_path: str, files: list[str] = None, overwrite: bool = True):
17
+ out_path = Path(out_path)
18
+
19
+ if overwrite:
20
+ if out_path.exists():
21
+ out_path.unlink()
22
+
23
+ # INITIALIZE EXCEL COM APP
24
+ try:
25
+ xlapp = win32.gencache.EnsureDispatch("Excel.Application")
26
+
27
+ # constants
28
+ xlPasteValues = -4163
29
+ lPasteFormats = -4122
30
+ xlWorkbookDefault = 51
31
+
32
+ # create new workbook
33
+ new_wb = xlapp.Workbooks.Add()
34
+ new_wb.SaveAs(Filename=str(out_path), FileFormat=xlWorkbookDefault)
35
+
36
+ dup_count = 1
37
+
38
+ for wb in files:
39
+ xlwb = xlapp.Workbooks.Open(wb)
40
+
41
+ for xlsh in xlwb.Worksheets:
42
+ new_sh = new_wb.Worksheets.Add()
43
+
44
+ try:
45
+ new_sh.Name = xlsh.Name
46
+
47
+ # Ugly non defined exception. Be aware that this wil caputre
48
+ except Exception as e:
49
+ new_sh.Name = f"{xlsh.Name}_{dup_count}"
50
+ dup_count += 1
51
+
52
+ new_wb.Save()
53
+ new_sh.Move(After=new_wb.Worksheets(new_wb.Worksheets.Count))
54
+
55
+ xlsh.Cells.Copy(new_sh.Cells)
56
+ new_sh = None
57
+
58
+ xlwb.Close(True)
59
+ xlwb = None
60
+
61
+ # remove default blad1
62
+ new_wb.Worksheets("Blad1").Delete()
63
+ new_wb.Save()
64
+
65
+ except Exception as e:
66
+ print(e)
67
+
68
+ # RELEASE RESOURCES
69
+ finally:
70
+ xlsh = None
71
+ new_sh = None
72
+ xlwb = None
73
+ new_wb = None
74
+ xlapp.Quit()
75
+ xlapp = None
76
+ xlwb = None
@@ -371,7 +371,7 @@ def cell_formatting(
371
371
  return fmt
372
372
 
373
373
 
374
- def write_worksheet(
374
+ def write_to_worksheet(
375
375
  ws: Any,
376
376
  arr: np.ndarray,
377
377
  fmt: Fmt,
@@ -497,6 +497,94 @@ def write_table(
497
497
  style: str = "old",
498
498
  combine_multiindex: bool | int = False,
499
499
  column_names_to_string: bool = True,
500
+ ):
501
+ wb = Workbook()
502
+ # Empty sheet is created on Workbook creation
503
+ del wb["Sheet"]
504
+
505
+ set_global_style(style)
506
+
507
+ if not isinstance(data, dict):
508
+ data = {"Sheet1": data}
509
+
510
+ for sheet_name, df in data.items():
511
+ if column_names_to_string == True:
512
+ df = cols_to_str(df)
513
+
514
+ format_worksheet(
515
+ wb=wb,
516
+ df=df,
517
+ sheet_name=sheet_name,
518
+ header_row=header_row,
519
+ title=title,
520
+ source=source,
521
+ total_row=total_row,
522
+ light_blue_row_ids=light_blue_row_ids,
523
+ total_col=total_col,
524
+ right_align_ids=right_align_ids,
525
+ right_align_pattern=right_align_pattern,
526
+ right_align_numeric=right_align_numeric,
527
+ left_align_ids=left_align_ids,
528
+ left_align_pattern=left_align_pattern,
529
+ left_align_string=left_align_string,
530
+ perc_ids=perc_ids,
531
+ perc_pattern=perc_pattern,
532
+ perc_col_format=perc_col_format,
533
+ blue_border=blue_border,
534
+ blue_border_row_ids=blue_border_row_ids,
535
+ number_format=number_format,
536
+ autofit_columns=autofit_columns,
537
+ col_filter=col_filter,
538
+ combine_multiindex=combine_multiindex,
539
+ column_names_to_string=column_names_to_string,
540
+ )
541
+
542
+ wb.save(file)
543
+
544
+
545
+ def write_table_from_dict(
546
+ file,
547
+ write_info,
548
+ style: str = "old",
549
+ ):
550
+ wb = Workbook()
551
+ # Empty sheet is created on Workbook creation
552
+ del wb["Sheet"]
553
+
554
+ set_global_style(style)
555
+
556
+ for sheet in write_info:
557
+ format_worksheet(wb=wb, **sheet)
558
+
559
+ wb.save(file)
560
+
561
+
562
+ def format_worksheet(
563
+ wb: Any,
564
+ df: pd.DataFrame,
565
+ sheet_name: str,
566
+ header_row: int = 0,
567
+ title: str | dict[str, str] | None = None,
568
+ source: str | None = None,
569
+ total_row: bool | None = None,
570
+ light_blue_row_ids: int | list[int] | None = None,
571
+ total_col: bool | None = None,
572
+ right_align_ids: list | None = None,
573
+ right_align_pattern: str | None = None,
574
+ right_align_numeric: bool | None = True,
575
+ left_align_ids: list | None = None,
576
+ left_align_pattern: str | None = None,
577
+ left_align_string: bool | None = True,
578
+ perc_ids: list | None = None,
579
+ perc_pattern: str | None = None,
580
+ perc_col_format: str | None = None,
581
+ blue_border: bool | None = True,
582
+ blue_border_row_ids: int | list[int] | None = None,
583
+ number_format: str = "0.0",
584
+ autofit_columns: str | None = "column_names",
585
+ col_filter: bool | None = False,
586
+ combine_multiindex: bool | int = False,
587
+ column_names_to_string: bool = True,
500
588
  ):
501
589
  """_summary_
502
590
 
@@ -519,124 +607,108 @@ def write_table(
519
607
  perc_col_format (str, optional): The formatting string of percentage columns. Defaults to None.
520
608
  col_filter (bool, optional): Set filter on columns. Defaults to False.
521
609
  """
610
+ arr = df_to_array(df)
611
+
612
+ blue_rows = []
613
+ light_blue_rows = []
614
+ light_blue_cols = []
615
+ blue_border_ids = []
616
+ r_align_ids = []
617
+ l_align_ids = []
618
+ p_ids = []
619
+ cells_to_merge = []
620
+ title_tbl = None
621
+ title_src = None
622
+
623
+ if isinstance(header_row, int):
624
+ blue_rows.extend(list(range(0, header_row + 1)))
522
625
 
523
- wb = Workbook()
524
- # Empty sheet is created on Workbook creation
525
- del wb["Sheet"]
526
-
527
- set_global_style(style)
528
-
529
- if not isinstance(data, dict):
530
- data = {"Sheet1": data}
531
-
532
- for sheet_name, df in data.items():
533
- if column_names_to_string == True:
534
- df = cols_to_str(df)
535
-
536
- arr = df_to_array(df)
537
-
538
- blue_rows = []
539
- light_blue_rows = []
540
- light_blue_cols = []
541
- blue_border_ids = []
542
- r_align_ids = []
543
- l_align_ids = []
544
- p_ids = []
545
- cells_to_merge = []
546
- title_tbl = None
547
- title_src = None
548
-
549
- if isinstance(header_row, int):
550
- blue_rows.extend(list(range(0, header_row + 1)))
551
-
552
- if title:
553
- if isinstance(title, str):
554
- title_tbl = title
555
- elif isinstance(title, dict):
556
- title_tbl = title.get(sheet_name)
557
-
558
- if source:
559
- if isinstance(source, str):
560
- title_src = source
561
- elif isinstance(title, dict):
562
- title_src = source.get(sheet_name)
563
-
564
- if right_align_ids:
565
- r_align_ids.extend(right_align_ids)
626
+ if title:
627
+ if isinstance(title, str):
628
+ title_tbl = title
629
+ elif isinstance(title, dict):
630
+ title_tbl = title.get(sheet_name)
566
631
 
567
- if right_align_pattern:
568
- r_align_ids.extend(get_cols_id_with_pattern(df, right_align_pattern))
632
+ if source:
633
+ if isinstance(source, str):
634
+ title_src = source
635
+ elif isinstance(title, dict):
636
+ title_src = source.get(sheet_name)
569
637
 
570
- if right_align_numeric:
571
- r_align_ids.extend(get_numeric_col_ids(df))
638
+ if right_align_ids:
639
+ r_align_ids.extend(right_align_ids)
572
640
 
573
- if left_align_ids:
574
- r_align_ids.extend(left_align_ids)
641
+ if right_align_pattern:
642
+ r_align_ids.extend(get_cols_id_with_pattern(df, right_align_pattern))
575
643
 
576
- if left_align_pattern:
577
- l_align_ids.extend(get_cols_id_with_pattern(df, left_align_pattern))
644
+ if right_align_numeric:
645
+ r_align_ids.extend(get_numeric_col_ids(df))
578
646
 
579
- if left_align_string:
580
- l_align_ids.extend(get_string_cols_ids(df))
647
+ if left_align_ids:
648
+ r_align_ids.extend(left_align_ids)
581
649
 
582
- if perc_ids:
583
- p_ids.extend(perc_ids)
650
+ if left_align_pattern:
651
+ l_align_ids.extend(get_cols_id_with_pattern(df, left_align_pattern))
584
652
 
585
- if perc_pattern:
586
- r_id = get_cols_id_with_pattern(df, perc_pattern)
587
- p_ids.extend(r_id)
588
- r_align_ids.extend(r_id)
653
+ if left_align_string:
654
+ l_align_ids.extend(get_string_cols_ids(df))
589
655
 
590
- if total_row:
591
- light_blue_rows.append(arr.shape[0] - 1)
656
+ if perc_ids:
657
+ p_ids.extend(perc_ids)
592
658
 
593
- if light_blue_row_ids:
594
- light_blue_rows.extend(light_blue_row_ids)
659
+ if perc_pattern:
660
+ r_id = get_cols_id_with_pattern(df, perc_pattern)
661
+ p_ids.extend(r_id)
662
+ r_align_ids.extend(r_id)
595
663
 
596
- if total_col:
597
- light_blue_cols.append(arr.shape[1] - 1)
664
+ if total_row:
665
+ light_blue_rows.append(arr.shape[0] - 1)
598
666
 
599
- if blue_border:
600
- blue_border_ids.append(arr.shape[0] - 1)
667
+ if light_blue_row_ids:
668
+ light_blue_rows.extend(light_blue_row_ids)
601
669
 
602
- if blue_border_row_ids:
603
- blue_border_ids.extend(blue_border_row_ids)
670
+ if total_col:
671
+ light_blue_cols.append(arr.shape[1] - 1)
604
672
 
605
- if combine_multiindex:
606
- cells_to_merge = get_cells_to_merge(df)
673
+ if blue_border:
674
+ blue_border_ids.append(arr.shape[0] - 1)
607
675
 
608
- if autofit_columns == "column_names":
609
- col_widths = get_max_col_widths(df)
610
- elif autofit_columns == "all_data":
611
- col_widths = get_max_col_widths(arr)
612
- else:
613
- col_widths = None
614
-
615
- ws = wb.create_sheet(sheet_name)
616
-
617
- fmt = cell_formatting(
618
- arr=arr,
619
- default_format=STYLES["calibri"],
620
- blue_row_ids=blue_rows,
621
- light_blue_row_ids=light_blue_rows,
622
- light_blue_col_ids=light_blue_cols,
623
- left_align_ids=l_align_ids,
624
- right_align_ids=r_align_ids,
625
- perc_col_ids=p_ids,
626
- perc_col_format=perc_col_format,
627
- number_format=number_format,
628
- blue_border_ids=blue_border_ids,
629
- )
676
+ if blue_border_row_ids:
677
+ blue_border_ids.extend(blue_border_row_ids)
630
678
 
631
- write_worksheet(
632
- ws=ws,
633
- arr=arr,
634
- fmt=fmt,
635
- title=title_tbl,
636
- source=title_src,
637
- col_filter=col_filter,
638
- col_widths=col_widths,
639
- cells_to_merge=cells_to_merge,
640
- )
679
+ if combine_multiindex:
680
+ cells_to_merge = get_cells_to_merge(df)
641
681
 
642
- wb.save(file)
682
+ if autofit_columns == "column_names":
683
+ col_widths = get_max_col_widths(df)
684
+ elif autofit_columns == "all_data":
685
+ col_widths = get_max_col_widths(arr)
686
+ else:
687
+ col_widths = None
688
+
689
+ ws = wb.create_sheet(sheet_name)
690
+
691
+ fmt = cell_formatting(
692
+ arr=arr,
693
+ default_format=STYLES["calibri"],
694
+ blue_row_ids=blue_rows,
695
+ light_blue_row_ids=light_blue_rows,
696
+ light_blue_col_ids=light_blue_cols,
697
+ left_align_ids=l_align_ids,
698
+ right_align_ids=r_align_ids,
699
+ perc_col_ids=p_ids,
700
+ perc_col_format=perc_col_format,
701
+ number_format=number_format,
702
+ blue_border_ids=blue_border_ids,
703
+ )
704
+
705
+ write_to_worksheet(
706
+ ws=ws,
707
+ arr=arr,
708
+ fmt=fmt,
709
+ title=title_tbl,
710
+ source=title_src,
711
+ col_filter=col_filter,
712
+ col_widths=col_widths,
713
+ cells_to_merge=cells_to_merge,
714
+ )
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: toolsos
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: OS tools
5
5
  Author-email: OS <d.schmitz@amsterdam.nl>
6
6
  Keywords: tools,Onderzoek & Statistiek
7
7
  Classifier: License :: OSI Approved :: MIT License
8
8
  Classifier: Programming Language :: Python
9
9
  Classifier: Programming Language :: Python :: 3
10
- Requires-Python: >=3.11
10
+ Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  Provides-Extra: dev
13
13
  Requires-Dist: black; extra == "dev"
@@ -1,6 +0,0 @@
1
- import pandas as pd
2
-
3
-
4
- def remove_underscores_from_columns(df: pd.DataFrame) -> pd.DataFrame:
5
- df.columns = df.columns.str.replace("_", " ")
6
- return df
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes