pl2html 0.6.0__tar.gz → 0.6.1__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.3
2
2
  Name: pl2html
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Summary: Add your description here
5
5
  Requires-Dist: polars>=1.42.1
6
6
  Requires-Python: >=3.14
@@ -0,0 +1 @@
1
+ __version__ = '0.6.1'
@@ -84,19 +84,16 @@ def _build_cell_expr(
84
84
 
85
85
  fmt_expr = fmt_expr.fill_null('')
86
86
 
87
- attr_expr_list = []
88
- if col_name in attrs:
89
- for attr_name, val_expr in attrs[col_name].items():
90
- val_str_expr = val_expr.cast(_String)
91
-
92
- compiled_attr = (
93
- _when(val_str_expr.is_not_null() & (val_str_expr != ''))
94
- .then(_lit(f' {attr_name}="') + val_str_expr + _lit('"'))
95
- .otherwise(_lit(''))
87
+ if col_attrs := attrs.get(col_name):
88
+ attr_expr_list = [
89
+ _when(
90
+ (val_str_expr := val_expr.cast(_String)).is_not_null()
91
+ & (val_str_expr != '')
96
92
  )
97
- attr_expr_list.append(compiled_attr)
98
-
99
- if attr_expr_list:
93
+ .then(_lit(f' {attr_name}="') + val_str_expr + _lit('"'))
94
+ .otherwise(_lit(''))
95
+ for attr_name, val_expr in col_attrs.items()
96
+ ]
100
97
  opening_td = _lit('<td') + _concat_str(attr_expr_list) + _lit('>')
101
98
  else:
102
99
  opening_td = _lit('<td>')
@@ -155,17 +152,6 @@ def _resolve_attributes(
155
152
  return lf, new_attrs
156
153
 
157
154
 
158
- def _apply_user_formatters(
159
- lf: _LazyFrame, formatters: _Expr | list[_Expr] | None
160
- ) -> _LazyFrame:
161
- """Applies layout transformation modifications/conversions to columns."""
162
- if formatters is None:
163
- return lf
164
- if isinstance(formatters, _Expr):
165
- formatters = [formatters]
166
- return lf.with_columns(formatters)
167
-
168
-
169
155
  def _compile_html(
170
156
  lf: _LazyFrame,
171
157
  visible_columns: list[str],
@@ -258,9 +244,7 @@ def to_html(
258
244
  """
259
245
  lf = df.lazy() if isinstance(df, _DataFrame) else df
260
246
  exclude_columns = exclude_columns or []
261
- attrs = attrs or {}
262
247
 
263
- # Setup the evaluation context data
264
248
  df_eager = lf.collect()
265
249
  lf = df_eager.lazy()
266
250
 
@@ -268,7 +252,12 @@ def to_html(
268
252
  c for c in df_eager.schema.names() if c not in exclude_columns
269
253
  ]
270
254
 
271
- lf, attrs = _resolve_attributes(lf, df_eager, attrs, visible_columns)
272
- lf = _apply_user_formatters(lf, formatters)
255
+ if attrs:
256
+ lf, attrs = _resolve_attributes(lf, df_eager, attrs, visible_columns)
257
+ else:
258
+ attrs = {}
259
+
260
+ if formatters is not None:
261
+ lf = lf.with_columns(formatters)
273
262
 
274
263
  return _compile_html(lf, visible_columns, attrs)
@@ -34,9 +34,24 @@ def _interpolate_segment(
34
34
  local_factor = (norm_val - seg_start) / segment_width
35
35
 
36
36
  # Linear interpolation formula applied directly to Polars Expressions
37
- r_expr = (_lit(r1) + (_lit(r2 - r1) * local_factor)).round(0).cast(_Int32)
38
- g_expr = (_lit(g1) + (_lit(g2 - g1) * local_factor)).round(0).cast(_Int32)
39
- b_expr = (_lit(b1) + (_lit(b2 - b1) * local_factor)).round(0).cast(_Int32)
37
+ r_expr = (
38
+ (_lit(r1) + (_lit(r2 - r1) * local_factor))
39
+ .fill_nan(None)
40
+ .round(0)
41
+ .cast(_Int32)
42
+ )
43
+ g_expr = (
44
+ (_lit(g1) + (_lit(g2 - g1) * local_factor))
45
+ .fill_nan(None)
46
+ .round(0)
47
+ .cast(_Int32)
48
+ )
49
+ b_expr = (
50
+ (_lit(b1) + (_lit(b2 - b1) * local_factor))
51
+ .fill_nan(None)
52
+ .round(0)
53
+ .cast(_Int32)
54
+ )
40
55
 
41
56
  return r_expr, g_expr, b_expr
42
57
 
@@ -4,7 +4,7 @@ build-backend = 'uv_build'
4
4
 
5
5
  [project]
6
6
  name = "pl2html"
7
- version = "0.6.0"
7
+ version = "0.6.1"
8
8
  description = "Add your description here"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.14"
@@ -1 +0,0 @@
1
- __version__ = '0.6.0'
File without changes
File without changes