pandas-plots 0.12.18__tar.gz → 0.12.20__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.
@@ -1,11 +1,11 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pandas-plots
3
- Version: 0.12.18
3
+ Version: 0.12.20
4
4
  Summary: A collection of helper for table handling and visualization
5
5
  Home-page: https://github.com/smeisegeier/pandas-plots
6
6
  Author: smeisegeier
7
7
  Author-email: dexterDSDo@googlemail.com
8
- License: MIT License
8
+ License: MIT
9
9
  Project-URL: Documentation, https://github.com/smeisegeier/pandas-plots
10
10
  Project-URL: Source Code, https://github.com/smeisegeier/pandas-plots
11
11
  Project-URL: Bug Tracker, https://github.com/smeisegeier/pandas-plots/issues
@@ -32,6 +32,7 @@ Requires-Dist: duckdb>=1.0.0
32
32
  Requires-Dist: kaleido>=0.2.0
33
33
  Requires-Dist: nbformat>=4.2.0
34
34
  Requires-Dist: dataframe_image>=0.2.6
35
+ Dynamic: license-file
35
36
 
36
37
  # pandas-plots
37
38
 
@@ -1,12 +1,12 @@
1
1
  [metadata]
2
2
  name = pandas-plots
3
- version = 0.12.18
3
+ version = 0.12.20
4
4
  author = smeisegeier
5
5
  author_email = dexterDSDo@googlemail.com
6
6
  description = A collection of helper for table handling and visualization
7
7
  long_description = file: README.md
8
8
  long_description_content_type = text/markdown
9
- license = MIT License
9
+ license = MIT
10
10
  license_files = LICENSE
11
11
  url = https://github.com/smeisegeier/pandas-plots
12
12
  project_urls =
@@ -522,33 +522,45 @@ def find_cols(all_cols: list[str], stubs: list[str] = None) -> list[str]:
522
522
  # * extend objects to enable chaining
523
523
  pd.DataFrame.find_cols = find_cols
524
524
 
525
- def add_measures_to_pyg_config(json_path: str, nodes: list[tuple[str, str]]) -> None:
525
+
526
+ def add_measures_to_pyg_config(json_path: str, nodes: list[tuple[str, str]] = [("cnt_tum", "count(distinct z_tum_id)")], strict: bool = False) -> None:
526
527
  """
527
- Reads a pygwalker json config file, adds new measures from given nodes if not already present, and writes back to the file.
528
+ Reads a pygwalker JSON config file, adds new measures from given nodes if not already present, and writes back to the file.
528
529
 
529
530
  Parameters
530
531
  ----------
531
532
  json_path : `str`
532
- The path to the pyg_json config file.
533
- nodes : `list[tuple[str, str]]`
534
- A list of tuples, where the first element in the tuple is the name of the measure and the second element is the SQL expression that defines the measure.
533
+ The path to the pygwalker JSON config file.
534
+ nodes : `list[tuple[str, str]]`, optional
535
+ A list of tuples, where the first element in the tuple is the name of the measure and the second element is the SQL expression that defines the measure. Default is `[('cnt_tum', 'count(distinct z_tum_id)')]`.
536
+ strict : `bool`, optional
537
+ If True, raises an error if the file does not exist or if JSON parsing fails. If False, the function exits silently in such cases. Default is False.
535
538
 
536
539
  Returns
537
540
  -------
538
541
  None
539
-
542
+
540
543
  Example
541
544
  -------
542
- `node = [("cnt_tum", "count(distinct z_tum_id)")]`
545
+ `add_measures_to_pyg_config('config.json', [('cnt_tum', 'count(distinct z_tum_id)')], strict=True)`
543
546
  """
544
-
545
- with open(json_path, "r", encoding="utf-8") as file:
546
- config = json.load(file)
547
+ if not os.path.exists(json_path):
548
+ if strict:
549
+ raise FileNotFoundError(f"File not found: {json_path}")
550
+ return
551
+
552
+ try:
553
+ with open(json_path, "r", encoding="utf-8") as file:
554
+ config = json.load(file)
555
+ except json.JSONDecodeError:
556
+ if strict:
557
+ raise
558
+ return
547
559
 
548
560
  for node in nodes:
549
561
  fid = uuid.uuid4().hex
550
562
 
551
- # Define the measure
563
+ # * Define the measure
552
564
  new_json_node = {
553
565
  "analyticType": "measure",
554
566
  "fid": f"{fid}",
@@ -563,13 +575,13 @@ def add_measures_to_pyg_config(json_path: str, nodes: list[tuple[str, str]]) ->
563
575
  }
564
576
  }
565
577
 
566
- # Get the measures list
567
- measures = config["config"][0]["encodings"]["measures"]
578
+ # * Get the measures list
579
+ measures = config.get("config", [{}])[0].get("encodings", {}).get("measures", [])
568
580
 
569
- # Ensure the measure is present
581
+ # * Ensure the measure is present
570
582
  if not any(measure.get("name") == node[0] for measure in measures):
571
583
  measures.append(new_json_node)
572
584
 
573
- # Write the updated JSON back to the file
585
+ # * Write the updated JSON back to the file
574
586
  with open(json_path, "w", encoding="utf-8") as file:
575
587
  json.dump(config, file, indent=2)
@@ -340,7 +340,7 @@ def plot_stacked_bars(
340
340
  _title_str_top_index = f"TOP{top_n_index} " if top_n_index > 0 else ""
341
341
  _title_str_top_color = f"TOP{top_n_color} " if top_n_color > 0 else ""
342
342
  _title_str_null = f", NULL excluded" if dropna else ""
343
- _title_str_n = f", n={n:_}"
343
+ _title_str_n = f", n={len(df):_} ({n:_})"
344
344
 
345
345
  _df = df.copy().assign(facet=None)
346
346
  _df.columns = (
@@ -653,7 +653,7 @@ def plot_bars(
653
653
 
654
654
  # * title str n
655
655
  _title_str_n = (
656
- f", n={n:_}" if not use_ci else f", n={n_len:_}<br><sub>ci(95) on means<sub>"
656
+ f", n={n_len:_} ({n:_})" if not use_ci else f", n={n_len:_})<br><sub>ci(95) on means<sub>"
657
657
  )
658
658
 
659
659
  # * title str na
@@ -1325,6 +1325,8 @@ def plot_facet_stacked_bars(
1325
1325
  df["value"] = 1
1326
1326
  elif df.shape[1] == 4:
1327
1327
  df.columns = ["index", "col", "facet", "value"]
1328
+
1329
+ n = df["value"].sum()
1328
1330
 
1329
1331
  aggregated_df = aggregate_data(
1330
1332
  df,
@@ -1427,7 +1429,7 @@ def plot_facet_stacked_bars(
1427
1429
  else:
1428
1430
  axis_details.append(f"[{original_column_names[2]}]")
1429
1431
 
1430
- title = f"{caption} {', '.join(axis_details)}, n = {original_rows:_}"
1432
+ title = f"{caption} {', '.join(axis_details)}, n = {original_rows:_} ({n:_})"
1431
1433
  template = "plotly_dark" if os.getenv("THEME") == "dark" else "plotly"
1432
1434
 
1433
1435
  fig.update_layout(
@@ -1,11 +1,11 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pandas-plots
3
- Version: 0.12.18
3
+ Version: 0.12.20
4
4
  Summary: A collection of helper for table handling and visualization
5
5
  Home-page: https://github.com/smeisegeier/pandas-plots
6
6
  Author: smeisegeier
7
7
  Author-email: dexterDSDo@googlemail.com
8
- License: MIT License
8
+ License: MIT
9
9
  Project-URL: Documentation, https://github.com/smeisegeier/pandas-plots
10
10
  Project-URL: Source Code, https://github.com/smeisegeier/pandas-plots
11
11
  Project-URL: Bug Tracker, https://github.com/smeisegeier/pandas-plots/issues
@@ -32,6 +32,7 @@ Requires-Dist: duckdb>=1.0.0
32
32
  Requires-Dist: kaleido>=0.2.0
33
33
  Requires-Dist: nbformat>=4.2.0
34
34
  Requires-Dist: dataframe_image>=0.2.6
35
+ Dynamic: license-file
35
36
 
36
37
  # pandas-plots
37
38
 
File without changes
File without changes