pandas-plots 0.12.16__tar.gz → 0.12.18__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,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pandas-plots
3
- Version: 0.12.16
3
+ Version: 0.12.18
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
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = pandas-plots
3
- version = 0.12.16
3
+ version = 0.12.18
4
4
  author = smeisegeier
5
5
  author_email = dexterDSDo@googlemail.com
6
6
  description = A collection of helper for table handling and visualization
@@ -471,7 +471,7 @@ pd.DataFrame.add_bitmask_label = add_bitmask_label
471
471
  ddb.DuckDBPyRelation.add_bitmask_label = add_bitmask_label
472
472
 
473
473
 
474
- def find_cols(all_cols: list[str], stubs=list[str]):
474
+ def find_cols(all_cols: list[str], stubs: list[str] = None):
475
475
  """
476
476
  Find all columns in a list of columns that contain any of the given stubs.
477
477
 
@@ -487,10 +487,38 @@ def find_cols(all_cols: list[str], stubs=list[str]):
487
487
  list[str]
488
488
  List of columns that contain any of the given stubs.
489
489
  """
490
- if all_cols is None or not stubs:
490
+ if all_cols is None or stubs is None:
491
491
  return "❌ empty lists"
492
492
  return [col for col in all_cols if any(match in col for match in stubs)]
493
493
 
494
+ def find_cols(all_cols: list[str], stubs: list[str] = None) -> list[str]:
495
+ """
496
+ Find all columns in a list of columns that contain any of the given stubs,
497
+ preserving the order of stubs in the output.
498
+
499
+ Parameters
500
+ ----------
501
+ all_cols : list[str]
502
+ List of columns to search in.
503
+ stubs : list[str], optional
504
+ List of strings to search for in column names.
505
+
506
+ Returns
507
+ -------
508
+ list[str]
509
+ List of columns that contain any of the given stubs, ordered by stubs.
510
+ """
511
+ if all_cols is None or not stubs:
512
+ print("❌ empty lists")
513
+ return []
514
+
515
+ result = []
516
+ for stub in stubs:
517
+ result.extend([col for col in all_cols if stub in col])
518
+
519
+ return result
520
+
521
+
494
522
  # * extend objects to enable chaining
495
523
  pd.DataFrame.find_cols = find_cols
496
524
 
@@ -661,7 +661,6 @@ def plot_bars(
661
661
 
662
662
  # * layot caption if provided
663
663
  caption = _set_caption(caption)
664
-
665
664
  # ! plot
666
665
  _fig = px.bar(
667
666
  df.sort_values(
@@ -674,7 +673,7 @@ def plot_bars(
674
673
  orientation=orientation,
675
674
  # * retrieve the original columns from series
676
675
  title=title
677
- or f"{caption}{_title_str_minval}{_title_str_top}[{df.columns[1]}] by [{col_index}]{_title_str_null}{_title_str_n}",
676
+ or f"{caption}{_title_str_minval}{_title_str_top}[{col_name}] by [{col_index}]{_title_str_null}{_title_str_n}",
678
677
  # * retrieve theme from env (intro.set_theme) or default
679
678
  template="plotly_dark" if os.getenv("THEME") == "dark" else "plotly",
680
679
  width=width,
@@ -732,8 +731,22 @@ def plot_bars(
732
731
 
733
732
  # * looks better on single bars
734
733
  _fig.update_traces(
735
- textposition="outside" if not use_ci else "auto", error_y=dict(thickness=5)
734
+ error_y=dict(thickness=5)
736
735
  )
736
+ if use_ci:
737
+ _fig.update_traces(
738
+ textposition="inside", # Put labels inside bars
739
+ insidetextanchor="start", # Align labels at the bottom
740
+ textfont=dict(size=14, color="white") # Adjust text color for visibility
741
+ )
742
+ else:
743
+ _fig.update_traces(
744
+ textposition="outside",
745
+ # error_y=dict(thickness=0)
746
+ )
747
+
748
+ # * set axis title
749
+
737
750
  _fig.show(renderer)
738
751
 
739
752
  # * save to png if path is provided
@@ -269,6 +269,7 @@ def pivot_df(
269
269
  alter_font: bool = True,
270
270
  font_size_th: int = 0,
271
271
  font_size_td: int = 0,
272
+ col1_width: int = 0,
272
273
  png_path: str | Path = None,
273
274
  png_conversion: Literal["chrome", "selenium"] = "selenium",
274
275
  ) -> pd.DataFrame:
@@ -306,6 +307,7 @@ def pivot_df(
306
307
  alter_font (bool, optional): Whether to alter the font. Defaults to True.
307
308
  font_size_th (int, optional): The font size for the header. Defaults to 0.
308
309
  font_size_td (int, optional): The font size for the table data. Defaults to 0.
310
+ col1_width (int, optional): The width of the first column in px. Defaults to 0.
309
311
  png_path (str | Path, optional): The path to save the output PNG file. Defaults to None.
310
312
  png_conversion (Literal["chrome", "selenium"], optional): The conversion method for the PNG file. Defaults to "selenium".
311
313
 
@@ -393,6 +395,7 @@ def pivot_df(
393
395
  alter_font=alter_font,
394
396
  font_size_th=font_size_th,
395
397
  font_size_td=font_size_td,
398
+ col1_width=col1_width,
396
399
  png_path=png_path,
397
400
  png_conversion=png_conversion,
398
401
 
@@ -416,6 +419,7 @@ def show_num_df(
416
419
  alter_font: bool = True,
417
420
  font_size_th: int = 0,
418
421
  font_size_td: int = 0,
422
+ col1_width: int = 0,
419
423
  png_path: str | Path = None,
420
424
  png_conversion: Literal["chrome", "selenium"] = "selenium",
421
425
  ):
@@ -445,6 +449,7 @@ def show_num_df(
445
449
  - alter_font: a boolean indicating whether to alter the font family
446
450
  - font_size_th: an integer indicating the font size for the header
447
451
  - font_size_td: an integer indicating the font size for the table data
452
+ - col1_width: an integer indicating the width of the first column in px
448
453
  - png_path: a string or Path indicating the path to save the PNG file
449
454
  - png_conversion: a Literal indicating the conversion method for the PNG file ["chrome", "selenium"]
450
455
 
@@ -680,6 +685,15 @@ def show_num_df(
680
685
  dict(selector="td", props=_props_td),
681
686
  ]
682
687
  )
688
+
689
+ if col1_width > 0:
690
+ out.set_table_styles([
691
+ {'selector': 'th:first-child, td:first-child',
692
+ 'props': [(f'min-width', f'{col1_width}px !important'),
693
+ (f'max-width', f'{col1_width}px !important'),
694
+ ('white-space', 'nowrap'),
695
+ ('overflow', 'hidden')]}
696
+ ])
683
697
 
684
698
  if heatmap_axis:
685
699
  out.background_gradient(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pandas-plots
3
- Version: 0.12.16
3
+ Version: 0.12.18
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
File without changes
File without changes