zedstat 0.0.151__tar.gz → 0.0.153__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.
Files changed (25) hide show
  1. {zedstat-0.0.151/zedstat.egg-info → zedstat-0.0.153}/PKG-INFO +2 -2
  2. zedstat-0.0.153/version.py +1 -0
  3. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/zedstat.py +172 -0
  4. {zedstat-0.0.151 → zedstat-0.0.153/zedstat.egg-info}/PKG-INFO +2 -2
  5. zedstat-0.0.151/version.py +0 -1
  6. {zedstat-0.0.151 → zedstat-0.0.153}/LICENSE +0 -0
  7. {zedstat-0.0.151 → zedstat-0.0.153}/MANIFEST.in +0 -0
  8. {zedstat-0.0.151 → zedstat-0.0.153}/README.rst +0 -0
  9. {zedstat-0.0.151 → zedstat-0.0.153}/setup.cfg +0 -0
  10. {zedstat-0.0.151 → zedstat-0.0.153}/setup.py +0 -0
  11. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/.ipynb_checkpoints/Untitled-Copy1-checkpoint.ipynb +0 -0
  12. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/.ipynb_checkpoints/Untitled-checkpoint.ipynb +0 -0
  13. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/.ipynb_checkpoints/example3-checkpoint.ipynb +0 -0
  14. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/__init__.py +0 -0
  15. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/calibration.py +0 -0
  16. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/ci.py +0 -0
  17. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/example_combine.py +0 -0
  18. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/mwauc.py +0 -0
  19. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/rrci.py +0 -0
  20. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/textable.py +0 -0
  21. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat/zcombine.py +0 -0
  22. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat.egg-info/SOURCES.txt +0 -0
  23. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat.egg-info/dependency_links.txt +0 -0
  24. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat.egg-info/requires.txt +0 -0
  25. {zedstat-0.0.151 → zedstat-0.0.153}/zedstat.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zedstat
3
- Version: 0.0.151
3
+ Version: 0.0.153
4
4
  Summary: Statistics tools for ML models and deployment
5
5
  Home-page: https://github.com/zeroknowledgediscovery/zedstat
6
- Download-URL: https://github.com/zeroknowledgediscovery/zedstat/archive/0.0.151.tar.gz
6
+ Download-URL: https://github.com/zeroknowledgediscovery/zedstat/archive/0.0.153.tar.gz
7
7
  Author: zed.uchicago.edu
8
8
  Author-email: ishanu@uchicago.edu
9
9
  License: LICENSE
@@ -0,0 +1 @@
1
+ __version__ = '0.0.153'
@@ -1746,3 +1746,175 @@ try:
1746
1746
  __all__.append('lr_nondominated_frontier')
1747
1747
  except Exception:
1748
1748
  pass
1749
+
1750
+
1751
+ # =============================================================================
1752
+ # NaN-safe final output accessor
1753
+ # =============================================================================
1754
+ # This accessor keeps the old behavior for zt.get(): nominal table only, no
1755
+ # interpolation. It adds two explicit final-output modes:
1756
+ # zt.get(bounds=True, interpolate=True)
1757
+ # returns nominal + upper/lower bounds and interpolates display gaps;
1758
+ # zt.get(0)
1759
+ # shorthand for the same NaN-safe final table. The 0 is not used as a
1760
+ # numerical fill value; residual all-NaN columns remain NaN unless fillna
1761
+ # is supplied explicitly.
1762
+
1763
+ _PROBABILITY_BASE_COLUMNS = {'tpr', 'ppv', 'acc', 'npv'}
1764
+
1765
+
1766
+ def _base_metric_name(col):
1767
+ col = str(col)
1768
+ for suffix in ('_upper', '_lower'):
1769
+ if col.endswith(suffix):
1770
+ return col[:-len(suffix)]
1771
+ return col
1772
+
1773
+
1774
+ def _clip_probability_like_columns(frame):
1775
+ out = frame.copy()
1776
+ for col in out.columns:
1777
+ if _base_metric_name(col) in _PROBABILITY_BASE_COLUMNS:
1778
+ vals = pd.to_numeric(out[col], errors='coerce').to_numpy(dtype=float)
1779
+ out[col] = np.clip(vals, 0.0, 1.0)
1780
+ return out
1781
+
1782
+
1783
+ def _interpolate_numeric_frame_for_display(frame, interpolate=True, fillna=None, limit_direction='both'):
1784
+ """Interpolate numeric display gaps in a final performance table.
1785
+
1786
+ This is intentionally a final accessor/post-processing step. It does not
1787
+ change the stored analytic bounds unless the caller assigns the returned
1788
+ dataframe. The main use is to prevent visualization breaks from NaNs that
1789
+ arise after endpoint masking, sparse empirical ROC rows, or frontier masking.
1790
+ """
1791
+ out = frame.copy().replace([np.inf, -np.inf], np.nan)
1792
+
1793
+ if interpolate:
1794
+ numeric_cols = [c for c in out.columns if pd.api.types.is_numeric_dtype(out[c])]
1795
+ if numeric_cols:
1796
+ idx_numeric = np.issubdtype(out.index.dtype, np.number)
1797
+ method = 'index' if idx_numeric else 'linear'
1798
+ out[numeric_cols] = out[numeric_cols].interpolate(
1799
+ method=method,
1800
+ limit_direction=limit_direction,
1801
+ axis=0,
1802
+ )
1803
+
1804
+ if fillna is not None:
1805
+ out = out.fillna(fillna)
1806
+
1807
+ out = _clip_probability_like_columns(out)
1808
+ return out
1809
+
1810
+
1811
+ def _enforce_joined_bounds_for_display(frame):
1812
+ """Ensure joined *_lower and *_upper columns bracket nominal columns."""
1813
+ out = frame.copy()
1814
+ for base in ['tpr', 'ppv', 'acc', 'npv', 'LR+', 'LR-']:
1815
+ lo_col = f'{base}_lower'
1816
+ hi_col = f'{base}_upper'
1817
+ if base not in out.columns or lo_col not in out.columns or hi_col not in out.columns:
1818
+ continue
1819
+
1820
+ n = pd.to_numeric(out[base], errors='coerce').to_numpy(dtype=float)
1821
+ lo = pd.to_numeric(out[lo_col], errors='coerce').to_numpy(dtype=float)
1822
+ hi = pd.to_numeric(out[hi_col], errors='coerce').to_numpy(dtype=float)
1823
+ finite = np.isfinite(n) & np.isfinite(lo) & np.isfinite(hi)
1824
+ if not np.any(finite):
1825
+ continue
1826
+
1827
+ lo2 = lo.copy()
1828
+ hi2 = hi.copy()
1829
+ lo2[finite] = np.minimum.reduce([lo[finite], hi[finite], n[finite]])
1830
+ hi2[finite] = np.maximum.reduce([lo[finite], hi[finite], n[finite]])
1831
+
1832
+ if base in _PROBABILITY_BASE_COLUMNS:
1833
+ lo2 = np.clip(lo2, 0.0, 1.0)
1834
+ hi2 = np.clip(hi2, 0.0, 1.0)
1835
+
1836
+ out[lo_col] = lo2
1837
+ out[hi_col] = hi2
1838
+ return out
1839
+
1840
+
1841
+ def _processRoc_get_nan_safe(
1842
+ self,
1843
+ interpolate=False,
1844
+ bounds=False,
1845
+ fillna=None,
1846
+ limit_direction='both',
1847
+ enforce_bounds=True,
1848
+ ):
1849
+ """Return the processed ROC table, optionally as a NaN-safe final table.
1850
+
1851
+ Parameters
1852
+ ----------
1853
+ interpolate : bool or numeric, default False
1854
+ False preserves the historical zt.get() behavior. True interpolates
1855
+ numeric gaps in the returned display table. Passing 0 is supported as a
1856
+ compact shorthand for zt.get(bounds=True, interpolate=True).
1857
+ bounds : bool, default False
1858
+ If True, join self.df_lim['U'] and self.df_lim['L'] using _upper and
1859
+ _lower suffixes before optional interpolation.
1860
+ fillna : scalar or None, default None
1861
+ Optional final fill for columns that remain NaN after interpolation.
1862
+ Leave as None to avoid inventing values for all-NaN columns.
1863
+ limit_direction : str, default 'both'
1864
+ Passed to pandas interpolate. 'both' fills endpoint display gaps using
1865
+ nearest finite values.
1866
+ enforce_bounds : bool, default True
1867
+ After interpolation, force lower <= nominal <= upper for joined bounds.
1868
+ """
1869
+ numeric_shorthand = isinstance(interpolate, (int, float, np.integer, np.floating)) and not isinstance(interpolate, (bool, np.bool_))
1870
+ if numeric_shorthand:
1871
+ # zt.get(0) means: return the final joined, interpolated display table.
1872
+ # The zero is not treated as a fill value because LR+ at FPR=0 should not
1873
+ # be replaced by zero. Use fillna=0 explicitly if that is actually wanted.
1874
+ if float(interpolate) != 0.0 and fillna is None:
1875
+ fillna = float(interpolate)
1876
+ interpolate = True
1877
+ bounds = True
1878
+
1879
+ out = self.df.copy()
1880
+
1881
+ if bounds:
1882
+ if 'U' not in self.df_lim or 'L' not in self.df_lim:
1883
+ raise ValueError("Bounds requested, but getBounds() has not been run yet.")
1884
+ out = (
1885
+ out
1886
+ .join(self.df_lim['U'], rsuffix='_upper')
1887
+ .join(self.df_lim['L'], rsuffix='_lower')
1888
+ )
1889
+
1890
+ if interpolate or fillna is not None:
1891
+ out = _interpolate_numeric_frame_for_display(
1892
+ out,
1893
+ interpolate=bool(interpolate),
1894
+ fillna=fillna,
1895
+ limit_direction=limit_direction,
1896
+ )
1897
+ if bounds and enforce_bounds:
1898
+ out = _enforce_joined_bounds_for_display(out)
1899
+
1900
+ return out.copy()
1901
+
1902
+
1903
+ def _processRoc_get_full(self, interpolate=True, fillna=None, limit_direction='both', enforce_bounds=True):
1904
+ """Convenience wrapper for the final nominal + bounds table."""
1905
+ return self.get(
1906
+ bounds=True,
1907
+ interpolate=interpolate,
1908
+ fillna=fillna,
1909
+ limit_direction=limit_direction,
1910
+ enforce_bounds=enforce_bounds,
1911
+ )
1912
+
1913
+
1914
+ processRoc.get = _processRoc_get_nan_safe
1915
+ processRoc.get_full = _processRoc_get_full
1916
+
1917
+ try:
1918
+ __all__.append('lr_nondominated_frontier')
1919
+ except Exception:
1920
+ pass
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zedstat
3
- Version: 0.0.151
3
+ Version: 0.0.153
4
4
  Summary: Statistics tools for ML models and deployment
5
5
  Home-page: https://github.com/zeroknowledgediscovery/zedstat
6
- Download-URL: https://github.com/zeroknowledgediscovery/zedstat/archive/0.0.151.tar.gz
6
+ Download-URL: https://github.com/zeroknowledgediscovery/zedstat/archive/0.0.153.tar.gz
7
7
  Author: zed.uchicago.edu
8
8
  Author-email: ishanu@uchicago.edu
9
9
  License: LICENSE
@@ -1 +0,0 @@
1
- __version__ = '0.0.151'
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes