openms-insight 0.1.1__py3-none-any.whl → 0.1.2__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.
@@ -8,6 +8,88 @@ import polars as pl
8
8
  import streamlit as st
9
9
 
10
10
 
11
+ def optimize_for_transfer(df: pl.DataFrame) -> pl.DataFrame:
12
+ """
13
+ Optimize DataFrame types for efficient Arrow transfer to frontend.
14
+
15
+ This function downcasts numeric types to reduce Arrow payload size and
16
+ avoid BigInt overhead in JavaScript:
17
+ - Int64 → Int32 (if values fit): Avoids BigInt conversion in JS
18
+ - Float64 → Float32: Sufficient precision for visualization
19
+
20
+ Args:
21
+ df: Polars DataFrame to optimize
22
+
23
+ Returns:
24
+ DataFrame with optimized types
25
+ """
26
+ if len(df) == 0:
27
+ return df
28
+
29
+ casts = []
30
+
31
+ for col in df.columns:
32
+ dtype = df[col].dtype
33
+
34
+ # Downcast Int64 to Int32 to avoid BigInt in JavaScript
35
+ # JS safe integer is 2^53, but Int32 range is simpler and sufficient for most data
36
+ if dtype == pl.Int64:
37
+ # Get min/max in a single pass
38
+ stats = df.select([
39
+ pl.col(col).min().alias('min'),
40
+ pl.col(col).max().alias('max'),
41
+ ]).row(0)
42
+ col_min, col_max = stats
43
+
44
+ if col_min is not None and col_max is not None:
45
+ # Int32 range: -2,147,483,648 to 2,147,483,647
46
+ if col_min >= -2147483648 and col_max <= 2147483647:
47
+ casts.append(pl.col(col).cast(pl.Int32))
48
+
49
+ # Downcast Float64 to Float32 (sufficient for display)
50
+ # Float32 has ~7 significant digits - enough for visualization
51
+ elif dtype == pl.Float64:
52
+ casts.append(pl.col(col).cast(pl.Float32))
53
+
54
+ if casts:
55
+ df = df.with_columns(casts)
56
+
57
+ return df
58
+
59
+
60
+ def optimize_for_transfer_lazy(lf: pl.LazyFrame) -> pl.LazyFrame:
61
+ """
62
+ Optimize LazyFrame types for efficient Arrow transfer (streaming-safe).
63
+
64
+ Unlike optimize_for_transfer(), this only applies optimizations that don't
65
+ require knowing the data values, preserving the ability to stream via sink_parquet().
66
+
67
+ Currently applies:
68
+ - Float64 → Float32: Always safe, no bounds check needed
69
+
70
+ Int64 → Int32 is NOT applied here because it requires bounds checking.
71
+ Use optimize_for_transfer() on collected DataFrames for full optimization.
72
+
73
+ Args:
74
+ lf: Polars LazyFrame to optimize
75
+
76
+ Returns:
77
+ LazyFrame with Float64 columns cast to Float32
78
+ """
79
+ schema = lf.collect_schema()
80
+ casts = []
81
+
82
+ for col, dtype in zip(schema.names(), schema.dtypes()):
83
+ # Only Float64 → Float32 is safe without bounds checking
84
+ if dtype == pl.Float64:
85
+ casts.append(pl.col(col).cast(pl.Float32))
86
+
87
+ if casts:
88
+ lf = lf.with_columns(casts)
89
+
90
+ return lf
91
+
92
+
11
93
  def _make_cache_key(
12
94
  filters: Dict[str, str],
13
95
  state: Dict[str, Any],
@@ -133,6 +215,8 @@ def _filter_and_collect(
133
215
  data = data.filter(pl.col(column) == selected_value)
134
216
 
135
217
  # Collect to Polars DataFrame
218
+ # Note: Type optimization (Int64→Int32, Float64→Float32) is applied at cache
219
+ # creation time in base.py._save_to_cache(), so data is already optimized
136
220
  df_polars = data.collect()
137
221
 
138
222
  # Compute hash efficiently (no pickle)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openms-insight
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Interactive visualization components for mass spectrometry data in Streamlit
5
5
  Project-URL: Homepage, https://github.com/t0mdavid-m/OpenMS-Insight
6
6
  Project-URL: Documentation, https://github.com/t0mdavid-m/OpenMS-Insight#readme
@@ -1,28 +1,28 @@
1
1
  openms_insight/__init__.py,sha256=-QMPUfCk1DwwlQKW6NFSZodRz-r82R4rJPOiWDf_mwA,830
2
2
  openms_insight/components/__init__.py,sha256=aNy1E8ttqQiiA5Ka9sviRy17gQT8lfc_EHsl1v1o-UQ,177
3
- openms_insight/components/heatmap.py,sha256=7nkNqdogEj6vnm90FeiTOyDtcy_vlb-HydcgZjmwSd4,34612
3
+ openms_insight/components/heatmap.py,sha256=VNlc3wgrzkujj0jmX4RN93yKhPPOvGXdo4YoyQ_elJs,36223
4
4
  openms_insight/components/lineplot.py,sha256=fcul7W2RZlTQBse6pDbTAS14_HE14gLDdsUZ-YLjgAQ,19948
5
5
  openms_insight/components/sequenceview.py,sha256=IPLyUiXTLYwdZ79B3pZDH1intUsjBIknTSLUQ2ftdD4,14359
6
6
  openms_insight/components/table.py,sha256=P2VIGcPf2iuVJ07rl1el_kTjUKBjlJ_PQeFQAO9sgbw,15361
7
7
  openms_insight/core/__init__.py,sha256=yKRgLfRm1CQm6ZGqQiyDwblzw2Qh3jw57U-ZSd63PYk,338
8
- openms_insight/core/base.py,sha256=IUtnLnoLz6yFRsyGrYaCRzmoh6Eq6dRdnpGj2owxnd4,15754
8
+ openms_insight/core/base.py,sha256=fkxAM9KVvzD6T8Guk3AeFWkNK4jeDgM3MbYPbmma8mw,16364
9
9
  openms_insight/core/cache.py,sha256=3fnPDWjuWUnxazK2XflcUIeRZZPQ3N45kAKYu-xGBKw,1197
10
10
  openms_insight/core/registry.py,sha256=iBb9xWvgOisxjVX74wtCvqWO20eBW5xH-XcNcVuW-Dg,2107
11
11
  openms_insight/core/state.py,sha256=VhY_3Yg-zbx9VsdqHElsNyD2UbJj6ApE4TRcUywDrjQ,6871
12
12
  openms_insight/core/subprocess_preprocess.py,sha256=E08qEyVinwRM_PXq0bZk-lHJcYeDHmdr3ok4yTRC63I,3155
13
13
  openms_insight/preprocessing/__init__.py,sha256=XFnxlvG-VRMrFbreGmFSIDqfYhev8WPUyZluadMmCgY,462
14
14
  openms_insight/preprocessing/compression.py,sha256=8oe-vqeSX-Xf1okPX0C0km2DRnl6Iz53Y1UgsLdMUPI,10499
15
- openms_insight/preprocessing/filtering.py,sha256=DuVdi7tofZyWbGqdRXJy8G1OYptmf1zxnPgsSoYU_zw,10423
15
+ openms_insight/preprocessing/filtering.py,sha256=ZG8P1RLzwJVGdhElXD6UOny0GFz-aNr0LesSKZPVJTA,13191
16
16
  openms_insight/rendering/__init__.py,sha256=i9MRFrAEAX5kjbOnMjw2woP_6mEaI6HcxtbrNwUxNaM,198
17
17
  openms_insight/rendering/bridge.py,sha256=cPZWMz07jKOcWkkL7FdCY8w1lNk8bME_1xuulCO3VgY,13146
18
18
  openms_insight/js-component/dist/index.html,sha256=LSJ3B_YmGUrCCdZ1UaZO2p6Wqsih6nTH62Z_0uZxpD8,430
19
19
  openms_insight/js-component/dist/assets/index.css,sha256=ACP0LGYUGQusvfDX9igw5DfoQr60P4IFgSqWhACY46A,884228
20
- openms_insight/js-component/dist/assets/index.js,sha256=DEqCo6eSi4pFuTafgsFg6imO1xe1g-Vx1KQsEAir3t4,6061023
20
+ openms_insight/js-component/dist/assets/index.js,sha256=9fkS8XuO6U_3-qnGhjpeiLnkacKZ9eDUGTbWyNgHwTc,6061688
21
21
  openms_insight/js-component/dist/assets/materialdesignicons-webfont.eot,sha256=CxgxBNL8XyYZbnc8d72vLgVQn9QlnS0V7O3Kebh-hPk,1307880
22
22
  openms_insight/js-component/dist/assets/materialdesignicons-webfont.ttf,sha256=YeirpaTpgf4iz3yOi82-oAR251xiw38Bv37jM2HWhCg,1307660
23
23
  openms_insight/js-component/dist/assets/materialdesignicons-webfont.woff,sha256=pZKKDVwvYk5G-Y2bFcL2AEU3f3xZTdeKF1kTLqO0Y-s,587984
24
24
  openms_insight/js-component/dist/assets/materialdesignicons-webfont.woff2,sha256=Zi_vqPL4qVwYWI0hd0eJwQfGTnccvmWmmvRikcQxGvw,403216
25
- openms_insight-0.1.1.dist-info/METADATA,sha256=_PtgWhRmLvKT0VsXjT9b8vQ7ZkSomdHGeD4sDmaUq_s,7385
26
- openms_insight-0.1.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
27
- openms_insight-0.1.1.dist-info/licenses/LICENSE,sha256=INFF4rOMmpah7Oi14hLqu7NTOsx56KRRNChAAUcfh2E,1823
28
- openms_insight-0.1.1.dist-info/RECORD,,
25
+ openms_insight-0.1.2.dist-info/METADATA,sha256=PZwmhlJVjzVeI23Ow3axp28YYg_84VxxsH9FrkFuRmg,7385
26
+ openms_insight-0.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
27
+ openms_insight-0.1.2.dist-info/licenses/LICENSE,sha256=INFF4rOMmpah7Oi14hLqu7NTOsx56KRRNChAAUcfh2E,1823
28
+ openms_insight-0.1.2.dist-info/RECORD,,