rgwfuncs 0.0.21__tar.gz → 0.0.23__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.21
3
+ Version: 0.0.23
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.21"
7
+ version = "0.0.23"
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.21
3
+ version = 0.0.23
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.
@@ -1709,27 +1708,36 @@ def print_n_frequency_linear(df: pd.DataFrame, n: int, columns: list, order_by:
1709
1708
 
1710
1709
  return report
1711
1710
 
1711
+ def try_parse_numeric(val):
1712
+ """Attempt to parse a value as an integer or float."""
1713
+ try:
1714
+ return int(val)
1715
+ except ValueError:
1716
+ try:
1717
+ return float(val)
1718
+ except ValueError:
1719
+ return val
1720
+
1712
1721
  def sort_frequency(frequency, order_by):
1713
- if order_by == "ASC":
1714
- return dict(sorted(frequency.items(), key=lambda item: item[0]))
1715
- elif order_by == "DESC":
1716
- return dict(
1717
- sorted(
1718
- frequency.items(),
1719
- key=lambda item: item[0],
1720
- reverse=True))
1721
- elif order_by == "FREQ_ASC":
1722
- return dict(sorted(frequency.items(), key=lambda item: item[1]))
1723
- elif order_by == "BY_KEYS_ASC":
1724
- return dict(sorted(frequency.items()))
1725
- elif order_by == "BY_KEYS_DESC":
1726
- return dict(sorted(frequency.items(), reverse=True))
1727
- else: # Default to "FREQ_DESC"
1728
- return dict(
1729
- sorted(
1730
- frequency.items(),
1731
- key=lambda item: item[1],
1732
- reverse=True))
1722
+ keys = frequency.keys()
1723
+
1724
+ # Convert keys to numerical values where possible, leaving `NaN` as a special string
1725
+ parsed_keys = [(try_parse_numeric(key), key) for key in keys]
1726
+
1727
+ if order_by in {"BY_KEYS_ASC", "BY_KEYS_DESC"}:
1728
+ reverse = order_by == "BY_KEYS_DESC"
1729
+ sorted_items = sorted(frequency.items(), key=lambda item: try_parse_numeric(item[0]), reverse=reverse)
1730
+ else:
1731
+ if order_by == "ASC":
1732
+ sorted_items = sorted(frequency.items(), key=lambda item: item[0])
1733
+ elif order_by == "DESC":
1734
+ sorted_items = sorted(frequency.items(), key=lambda item: item[0], reverse=True)
1735
+ elif order_by == "FREQ_ASC":
1736
+ sorted_items = sorted(frequency.items(), key=lambda item: item[1])
1737
+ else: # Default to "FREQ_DESC"
1738
+ sorted_items = sorted(frequency.items(), key=lambda item: item[1], reverse=True)
1739
+
1740
+ return dict(sorted_items)
1733
1741
 
1734
1742
  report = generate_linear_report(df, columns, n, order_by)
1735
1743
  print(json.dumps(report, indent=2))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: rgwfuncs
3
- Version: 0.0.21
3
+ Version: 0.0.23
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