rgwfuncs 0.0.21__py3-none-any.whl → 0.0.22__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.
rgwfuncs/df_lib.py CHANGED
@@ -1672,7 +1672,6 @@ def print_n_frequency_cascading(
1672
1672
  report = generate_cascade_report(df, columns, n, order_by)
1673
1673
  print(json.dumps(report, indent=2))
1674
1674
 
1675
-
1676
1675
  def print_n_frequency_linear(df: pd.DataFrame, n: int, columns: list, order_by: str = "FREQ_DESC") -> None:
1677
1676
  """
1678
1677
  Print the linear frequency of top n values for specified columns.
@@ -1709,7 +1708,21 @@ def print_n_frequency_linear(df: pd.DataFrame, n: int, columns: list, order_by:
1709
1708
 
1710
1709
  return report
1711
1710
 
1711
+ def can_convert_keys_to_int(keys):
1712
+ """Helper function to check if all keys can be converted to integers."""
1713
+ try:
1714
+ [int(key) for key in keys]
1715
+ return True
1716
+ except ValueError:
1717
+ return False
1718
+
1712
1719
  def sort_frequency(frequency, order_by):
1720
+ keys = frequency.keys()
1721
+
1722
+ # Determine if we can sort by integer values of keys
1723
+ if can_convert_keys_to_int(keys):
1724
+ keys = list(map(int, keys)) # Convert keys to integers, and keep original order
1725
+
1713
1726
  if order_by == "ASC":
1714
1727
  return dict(sorted(frequency.items(), key=lambda item: item[0]))
1715
1728
  elif order_by == "DESC":
@@ -1721,9 +1734,15 @@ def print_n_frequency_linear(df: pd.DataFrame, n: int, columns: list, order_by:
1721
1734
  elif order_by == "FREQ_ASC":
1722
1735
  return dict(sorted(frequency.items(), key=lambda item: item[1]))
1723
1736
  elif order_by == "BY_KEYS_ASC":
1724
- return dict(sorted(frequency.items()))
1737
+ if isinstance(keys[0], int):
1738
+ return dict(sorted(frequency.items(), key=lambda item: int(item[0])))
1739
+ else:
1740
+ return dict(sorted(frequency.items()))
1725
1741
  elif order_by == "BY_KEYS_DESC":
1726
- return dict(sorted(frequency.items(), reverse=True))
1742
+ if isinstance(keys[0], int):
1743
+ return dict(sorted(frequency.items(), key=lambda item: int(item[0]), reverse=True))
1744
+ else:
1745
+ return dict(sorted(frequency.items(), reverse=True))
1727
1746
  else: # Default to "FREQ_DESC"
1728
1747
  return dict(
1729
1748
  sorted(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.21
3
+ Version: 0.0.22
4
4
  Summary: A functional programming paradigm for mathematical modelling and data science
5
5
  Home-page: https://github.com/ryangerardwilson/rgwfunc
6
6
  Author: Ryan Gerard Wilson
@@ -0,0 +1,9 @@
1
+ rgwfuncs/__init__.py,sha256=2nrp3c5VmVrKh0Ih6zELL8niH9nAHN0XnObqe-EpxlE,1169
2
+ rgwfuncs/df_lib.py,sha256=nd-F7NGraUINuZUIqYHo2QwUNTjESgBlxKDQbbqlhS8,68050
3
+ rgwfuncs/str_lib.py,sha256=I5B0WOGaLUGaedMG7hqiKnIqV7Jc9h1RYlgOiC_-iGY,3678
4
+ rgwfuncs-0.0.22.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
5
+ rgwfuncs-0.0.22.dist-info/METADATA,sha256=aQ86F5Sb5XUGej267Y-hwVuAYqObbuNfy5vcbCxmgYY,34680
6
+ rgwfuncs-0.0.22.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
+ rgwfuncs-0.0.22.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
8
+ rgwfuncs-0.0.22.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
9
+ rgwfuncs-0.0.22.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- rgwfuncs/__init__.py,sha256=2nrp3c5VmVrKh0Ih6zELL8niH9nAHN0XnObqe-EpxlE,1169
2
- rgwfuncs/df_lib.py,sha256=URN-ChKH7JUGcKeLVURGf5RrZS8psCWs5w7dkbtKmCk,67252
3
- rgwfuncs/str_lib.py,sha256=I5B0WOGaLUGaedMG7hqiKnIqV7Jc9h1RYlgOiC_-iGY,3678
4
- rgwfuncs-0.0.21.dist-info/LICENSE,sha256=7EI8xVBu6h_7_JlVw-yPhhOZlpY9hP8wal7kHtqKT_E,1074
5
- rgwfuncs-0.0.21.dist-info/METADATA,sha256=P0BVo_B-RPIjFzEGApdjjBTNuyE3wtiKgjhcrB35yPE,34680
6
- rgwfuncs-0.0.21.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- rgwfuncs-0.0.21.dist-info/entry_points.txt,sha256=j-c5IOPIQ0252EaOV6j6STio56sbXl2C4ym_fQ0lXx0,43
8
- rgwfuncs-0.0.21.dist-info/top_level.txt,sha256=aGuVIzWsKiV1f2gCb6mynx0zx5ma0B1EwPGFKVEMTi4,9
9
- rgwfuncs-0.0.21.dist-info/RECORD,,