pandas-plots 0.12.19__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
1
  Metadata-Version: 2.4
2
2
  Name: pandas-plots
3
- Version: 0.12.19
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"
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
@@ -1,12 +1,12 @@
1
1
  [metadata]
2
2
  name = pandas-plots
3
- version = 0.12.19
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"
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)
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pandas-plots
3
- Version: 0.12.19
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"
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
File without changes
File without changes