rgwfuncs 0.0.20__tar.gz → 0.0.22__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: rgwfuncs
3
- Version: 0.0.20
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rgwfuncs"
7
- version = "0.0.20"
7
+ version = "0.0.22"
8
8
  authors = [
9
9
  { name = "Ryan Gerard Wilson", email = "ryangerardwilson@gmail.com" },
10
10
  ]
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = rgwfuncs
3
- version = 0.0.20
3
+ version = 0.0.22
4
4
  author = Ryan Gerard Wilson
5
5
  author_email = ryangerardwilson@gmail.com
6
6
  description = A functional programming paradigm for mathematical modelling and data science
@@ -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.
@@ -1681,7 +1680,7 @@ def print_n_frequency_linear(df: pd.DataFrame, n: int, columns: list, order_by:
1681
1680
  df: DataFrame to analyze.
1682
1681
  n: Number of top values to print.
1683
1682
  columns: List of column names to analyze.
1684
- order_by: Order of frequency: ASC, DESC, FREQ_ASC, FREQ_DESC.
1683
+ order_by: Order of frequency: ASC, DESC, FREQ_ASC, FREQ_DESC, BY_KEYS_ASC, BY_KEYS_DESC.
1685
1684
  """
1686
1685
 
1687
1686
  def generate_linear_report(df, columns, limit, order_by):
@@ -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":
@@ -1720,6 +1733,16 @@ def print_n_frequency_linear(df: pd.DataFrame, n: int, columns: list, order_by:
1720
1733
  reverse=True))
1721
1734
  elif order_by == "FREQ_ASC":
1722
1735
  return dict(sorted(frequency.items(), key=lambda item: item[1]))
1736
+ elif order_by == "BY_KEYS_ASC":
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()))
1741
+ elif order_by == "BY_KEYS_DESC":
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))
1723
1746
  else: # Default to "FREQ_DESC"
1724
1747
  return dict(
1725
1748
  sorted(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.20
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
File without changes
File without changes