analog-daddy 3.0.1.dev1__tar.gz → 3.0.1.dev3__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026, Siddhant Laddha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,60 @@
1
+ Metadata-Version: 2.4
2
+ Name: analog-daddy
3
+ Version: 3.0.1.dev3
4
+ Summary: This library is an attempt to make transistor sizing for Analog Design less painful. Additionally, provides helper utilities to minimize churn and errors in repetative tasks.
5
+ Author: Sid L
6
+ Author-email: Sid L <25705822+sidm273@users.noreply.github.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Education
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: boltons
21
+ Requires-Dist: cyclopts ; sys_platform != 'emscripten'
22
+ Requires-Dist: great-tables
23
+ Requires-Dist: plotly
24
+ Requires-Dist: polars
25
+ Requires-Dist: pydantic>=2
26
+ Requires-Dist: pydantic-settings
27
+ Requires-Dist: quantiphy
28
+ Requires-Dist: rich
29
+ Requires-Dist: scipy
30
+ Requires-Dist: xarray
31
+ Requires-Dist: marimo[lsp,mcp,recommended] ; extra == 'notebooks'
32
+ Requires-Dist: wigglystuff ; extra == 'notebooks'
33
+ Maintainer: Sid L
34
+ Maintainer-email: Sid L <25705822+sidm273@users.noreply.github.com>
35
+ Requires-Python: >=3.12
36
+ Project-URL: bugs, https://github.com/sidm273/analog_daddy/issues
37
+ Project-URL: changelog, https://github.com/sidm273/analog_daddy/releases
38
+ Project-URL: documentation, https://sidm273.github.io/analog_daddy/
39
+ Project-URL: homepage, https://github.com/sidm273/analog_daddy
40
+ Provides-Extra: notebooks
41
+ Description-Content-Type: text/markdown
42
+
43
+ # Analog Daddy
44
+
45
+ [![actions-badge]][actions-link]
46
+
47
+ [![PyPI version][pypi-version]][pypi-link]
48
+ [![PyPI platforms][pypi-platforms]][pypi-link]
49
+
50
+ <!-- prettier-ignore-start -->
51
+ [actions-badge]: https://github.com/sidm273/analog-daddy/actions/workflows/ci.yml/badge.svg
52
+ [actions-link]: https://github.com/sidm273/analog-daddy/actions
53
+ [pypi-link]: https://pypi.org/project/analog-daddy/
54
+ [pypi-platforms]: https://img.shields.io/pypi/pyversions/analog-daddy
55
+ [pypi-version]: https://img.shields.io/pypi/v/analog-daddy
56
+
57
+ <!-- prettier-ignore-end -->
58
+
59
+ This is a dummy README for the dev version. Please refer
60
+ [main](https://github.com/sidm273/analog-daddy)
@@ -0,0 +1,18 @@
1
+ # Analog Daddy
2
+
3
+ [![actions-badge]][actions-link]
4
+
5
+ [![PyPI version][pypi-version]][pypi-link]
6
+ [![PyPI platforms][pypi-platforms]][pypi-link]
7
+
8
+ <!-- prettier-ignore-start -->
9
+ [actions-badge]: https://github.com/sidm273/analog-daddy/actions/workflows/ci.yml/badge.svg
10
+ [actions-link]: https://github.com/sidm273/analog-daddy/actions
11
+ [pypi-link]: https://pypi.org/project/analog-daddy/
12
+ [pypi-platforms]: https://img.shields.io/pypi/pyversions/analog-daddy
13
+ [pypi-version]: https://img.shields.io/pypi/v/analog-daddy
14
+
15
+ <!-- prettier-ignore-end -->
16
+
17
+ This is a dummy README for the dev version. Please refer
18
+ [main](https://github.com/sidm273/analog-daddy)
@@ -1,14 +1,21 @@
1
1
  [project]
2
2
  name = "analog-daddy"
3
- version = "3.0.1.dev1"
3
+ version = "3.0.1.dev3"
4
4
  description = "This library is an attempt to make transistor sizing for Analog Design less painful. Additionally, provides helper utilities to minimize churn and errors in repetative tasks."
5
5
  readme = "README.md"
6
6
  requires-python = ">= 3.12"
7
7
  license = "MIT"
8
+ license-files = ["LICENSE"]
8
9
  classifiers = [
9
10
  "Development Status :: 4 - Beta",
10
11
  "Intended Audience :: Education",
11
12
  "Intended Audience :: Science/Research",
13
+ "Programming Language :: Python",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3 :: Only",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
12
19
  "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
13
20
  "Typing :: Typed",
14
21
  ]
@@ -27,28 +34,32 @@ dependencies = [
27
34
  ]
28
35
 
29
36
  [[project.authors]]
30
- name = "Siddhant Laddha"
31
- email = "25705822+siddhantladdha@users.noreply.github.com"
37
+ name = "Sid L"
38
+ email = "25705822+sidm273@users.noreply.github.com"
32
39
 
33
40
  [[project.maintainers]]
34
- name = "Siddhant Laddha"
35
- email = "25705822+siddhantladdha@users.noreply.github.com"
41
+ name = "Sid L"
42
+ email = "25705822+sidm273@users.noreply.github.com"
36
43
 
37
44
  [project.urls]
38
- bugs = "https://github.com/siddhantladdha/analog_daddy/issues"
39
- changelog = "https://github.com/siddhantladdha/analog_daddy/releases"
40
- documentation = "https://siddhantladdha.github.io/analog_daddy/"
41
- homepage = "https://github.com/siddhantladdha/analog_daddy"
45
+ bugs = "https://github.com/sidm273/analog_daddy/issues"
46
+ changelog = "https://github.com/sidm273/analog_daddy/releases"
47
+ documentation = "https://sidm273.github.io/analog_daddy/"
48
+ homepage = "https://github.com/sidm273/analog_daddy"
42
49
 
43
50
  [project.scripts]
44
51
  analog_daddy = "analog_daddy.cli:app"
45
52
 
53
+ [project.optional-dependencies]
54
+ notebooks = [
55
+ "marimo[lsp,mcp,recommended]",
56
+ "wigglystuff",
57
+ ]
58
+
46
59
  [dependency-groups]
47
- dev = [
48
- "format-docstring",
49
- "pytest",
50
- "ruff",
51
- "ty",
60
+ all = [
61
+ "analog-daddy[notebooks]",
62
+ { include-group = "dev" },
52
63
  ]
53
64
  docs = [
54
65
  "mkdocstrings-python",
@@ -56,20 +67,25 @@ docs = [
56
67
  "playwright",
57
68
  "zensical",
58
69
  ]
59
- lint = ["pydoclint"]
60
- notebooks = [
61
- "marimo[lsp,mcp,recommended]",
62
- "wigglystuff",
70
+ lint = [
71
+ "format-docstring",
72
+ "ruff",
73
+ "ty",
74
+ ]
75
+ lint_isolated = ["pydoclint"]
76
+ testing = [
77
+ "hypothesis",
78
+ "pytest >= 9",
63
79
  ]
64
80
 
65
- [[dependency-groups.all]]
66
- include-group = "dev"
67
-
68
- [[dependency-groups.all]]
81
+ [[dependency-groups.dev]]
69
82
  include-group = "docs"
70
83
 
71
- [[dependency-groups.all]]
72
- include-group = "notebooks"
84
+ [[dependency-groups.dev]]
85
+ include-group = "lint"
86
+
87
+ [[dependency-groups.dev]]
88
+ include-group = "testing"
73
89
 
74
90
  [build-system]
75
91
  requires = ["uv_build>=0.13.0,<0.14"]
@@ -93,12 +109,19 @@ check-style-mismatch = true
93
109
  show-filenames-in-every-violation-message = true
94
110
  exclude = '\.git|\.tox|\.venv|build|dist|.*drafts.*\.py'
95
111
 
96
- [tool.pytest.ini_options]
112
+ [tool.pytest]
97
113
  addopts = [
114
+ "--report-chars=A",
98
115
  "--doctest-modules",
99
116
  "--ignore-glob=*drafts*.py",
117
+ "--doctest-report=cdiff",
118
+ ]
119
+ doctest_optionflags = [
120
+ "IGNORE_EXCEPTION_DETAIL",
121
+ "NUMBER",
100
122
  ]
101
- doctest_optionflags = ["IGNORE_EXCEPTION_DETAIL"]
123
+ log_level = "INFO"
124
+ minversion = "9.0"
102
125
  testpaths = [
103
126
  "src",
104
127
  "tests",
@@ -108,6 +131,7 @@ testpaths = [
108
131
  line-length = 79
109
132
  extend-exclude = ["*drafts*.py"]
110
133
  output-prefer-rule-codes = true
134
+ show-fixes = true
111
135
 
112
136
  [tool.ruff.lint]
113
137
  ignore = [
@@ -115,8 +139,19 @@ ignore = [
115
139
  "D401",
116
140
  ]
117
141
  extend-select = [
142
+ "ARG",
143
+ "B",
144
+ "EM",
145
+ "G",
146
+ "ISC",
147
+ "Q",
148
+ "RET",
149
+ "RSE",
150
+ "RUF",
118
151
  "NPY",
152
+ "C4",
119
153
  "N",
154
+ "ICN",
120
155
  "PTH",
121
156
  "SIM",
122
157
  "EXE",
@@ -1,20 +1,27 @@
1
1
  [project]
2
2
  name = "analog-daddy"
3
- version = "3.0.1.dev1"
3
+ version = "3.0.1.dev3"
4
4
  description = "This library is an attempt to make transistor sizing for Analog Design less painful. Additionally, provides helper utilities to minimize churn and errors in repetative tasks."
5
5
  readme = "README.md"
6
6
  requires-python = ">= 3.12"
7
7
  license = "MIT"
8
+ license-files = ["LICENSE"]
8
9
  authors = [
9
- { name = "Siddhant Laddha", email = "25705822+siddhantladdha@users.noreply.github.com" }
10
+ { name = "Sid L", email = "25705822+sidm273@users.noreply.github.com" }
10
11
  ]
11
12
  maintainers = [
12
- { name = "Siddhant Laddha", email = "25705822+siddhantladdha@users.noreply.github.com" }
13
+ { name = "Sid L", email = "25705822+sidm273@users.noreply.github.com" }
13
14
  ]
14
15
  classifiers = [
15
16
  "Development Status :: 4 - Beta",
16
17
  "Intended Audience :: Education",
17
18
  "Intended Audience :: Science/Research",
19
+ "Programming Language :: Python",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
18
25
  "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
19
26
  "Typing :: Typed",
20
27
  ]
@@ -33,25 +40,30 @@ dependencies = [
33
40
  ]
34
41
 
35
42
  [project.urls]
36
- bugs = "https://github.com/siddhantladdha/analog_daddy/issues"
37
- changelog = "https://github.com/siddhantladdha/analog_daddy/releases"
38
- documentation = "https://siddhantladdha.github.io/analog_daddy/"
39
- homepage = "https://github.com/siddhantladdha/analog_daddy"
43
+ bugs = "https://github.com/sidm273/analog_daddy/issues"
44
+ changelog = "https://github.com/sidm273/analog_daddy/releases"
45
+ documentation = "https://sidm273.github.io/analog_daddy/"
46
+ homepage = "https://github.com/sidm273/analog_daddy"
40
47
 
41
48
  [project.scripts]
42
49
  analog_daddy = "analog_daddy.cli:app"
43
50
 
51
+ [project.optional-dependencies]
52
+ notebooks = [
53
+ "marimo[lsp,mcp,recommended]",
54
+ "wigglystuff",
55
+ ]
56
+
44
57
  [dependency-groups]
45
58
  dev = [
46
- "format-docstring",
47
- "pytest",
48
- "ruff",
49
- "ty",
59
+ { include-group = "docs" },
60
+ { include-group = "lint" },
61
+ { include-group = "testing" },
50
62
  ]
63
+
51
64
  all = [
65
+ "analog-daddy[notebooks]",
52
66
  { include-group = "dev" },
53
- { include-group = "docs" },
54
- { include-group = "notebooks" },
55
67
  ]
56
68
  docs = [
57
69
  "mkdocstrings-python",
@@ -60,11 +72,14 @@ docs = [
60
72
  "zensical",
61
73
  # TODO: evaluate vs great-docs for marimo notebooks in docs.
62
74
  ]
63
- lint = ["pydoclint"]
64
- notebooks = [
65
- "marimo[lsp,mcp,recommended]",
66
- "wigglystuff",
75
+ lint = [
76
+ "format-docstring",
77
+ "ruff",
78
+ "ty",
67
79
  ]
80
+ # pydoclint has issues with cyclopts.
81
+ lint_isolated = ["pydoclint"]
82
+ testing = ["hypothesis", "pytest >= 9"]
68
83
 
69
84
  [build-system]
70
85
  requires = ["uv_build>=0.13.0,<0.14"]
@@ -89,15 +104,23 @@ check-style-mismatch = true
89
104
  show-filenames-in-every-violation-message = true
90
105
  exclude = '\.git|\.tox|\.venv|build|dist|.*drafts.*\.py'
91
106
 
92
- [tool.pytest.ini_options]
93
- addopts = ["--doctest-modules", "--ignore-glob=*drafts*.py"]
94
- doctest_optionflags = ["IGNORE_EXCEPTION_DETAIL"]
107
+ [tool.pytest]
108
+ addopts = [
109
+ "--report-chars=A",
110
+ "--doctest-modules",
111
+ "--ignore-glob=*drafts*.py",
112
+ "--doctest-report=cdiff",
113
+ ]
114
+ doctest_optionflags = ["IGNORE_EXCEPTION_DETAIL", "NUMBER"]
115
+ log_level = "INFO"
116
+ minversion = "9.0"
95
117
  testpaths = ["src", "tests"]
96
118
 
97
119
  [tool.ruff]
98
120
  line-length = 79
99
121
  extend-exclude = ["*drafts*.py"]
100
122
  output-prefer-rule-codes = true
123
+ show-fixes = true
101
124
 
102
125
  [tool.ruff.lint]
103
126
  ignore = [
@@ -109,9 +132,20 @@ ignore = [
109
132
  "D401", # non-imperative-mood
110
133
  ]
111
134
  extend-select = [
135
+ "ARG", # flake8-unused-arguments
136
+ "B", # flake8-bugbear
137
+ "EM", # flake8-errmsg
138
+ "G", # flake8-logging-format
139
+ "ISC", # flake8-implicit-str-concat
140
+ "Q", # flake8-quotes
141
+ "RET", # flake8-return
142
+ "RSE", # flake8-raise
143
+ "RUF", # Ruff-specific
112
144
  "NPY", # numpy
113
145
  # "D", # docstring # handled by format-docstring and pydoclint
146
+ "C4", # flake8-comprehensions
114
147
  "N", # pep8-naming
148
+ "ICN", # flake8-import-conventions
115
149
  "PTH", # flake8-use-pathlib
116
150
  "SIM", # flake8-simplify
117
151
  "EXE", # flake8-executable
@@ -0,0 +1,7 @@
1
+ """Top-level package for Analog Daddy."""
2
+
3
+ from importlib.metadata import version
4
+
5
+ __version__ = version("analog-daddy")
6
+
7
+ __all__ = ["__version__"]
@@ -1,8 +1,9 @@
1
1
  import polars.selectors as cs
2
2
  from great_tables import GT
3
3
 
4
+ __all__ = ["gt_defaults"]
5
+
4
6
 
5
7
  def gt_defaults(gtbl: GT):
6
8
  """Preferred defaults for rendering great tables."""
7
- gtbl = gtbl.fmt_number_si(columns=cs.numeric()).opt_stylize(style=4)
8
- return gtbl
9
+ return gtbl.fmt_number_si(columns=cs.numeric()).opt_stylize(style=4)
@@ -14,9 +14,16 @@ import marimo as mo
14
14
  import polars as pl
15
15
  import polars.selectors as cs
16
16
  from rich.console import Console, RenderableType
17
+ from wigglystuff import CopyToClipboard
17
18
 
18
19
  from analog_daddy.utils import render
19
20
 
21
+ __all__ = [
22
+ "df_repr_docstr_clip",
23
+ "mo_table",
24
+ "rich_md",
25
+ ]
26
+
20
27
 
21
28
  def format_mapping_num_to_si(df: pl.DataFrame) -> dict[str, Callable]:
22
29
  """
@@ -121,3 +128,35 @@ def rich_md(
121
128
  console = Console(file=capture, **console_kwargs)
122
129
  console.print(*renderables, **print_kwargs)
123
130
  return mo.Html(console.export_html(**export_html_kwargs))
131
+
132
+
133
+ def df_repr_docstr_clip(
134
+ df: pl.DataFrame, max_rows: int = 3
135
+ ) -> CopyToClipboard:
136
+ """
137
+ Copy the repr of a polars DataFrame to the clipboard.
138
+
139
+ Parameters
140
+ ----------
141
+ df : pl.DataFrame
142
+ The DataFrame to copy the repr of.
143
+ max_rows : int, default=3
144
+ The maximum number of rows to include in the repr.
145
+
146
+ Returns
147
+ -------
148
+ CopyToClipboard
149
+ A CopyToClipboard object containing the repr of the DataFrame.
150
+
151
+ Examples
152
+ --------
153
+ >>> a = pl.DataFrame(
154
+ ... {"x": [9.0, 11.0], "foo": [10.0, 10.0], "bar": [5.0, 5.0]},
155
+ ... )
156
+ >>> df_repr_docstr_clip(a).text_to_copy.startswith("shape: (2, 3)")
157
+ True
158
+ """
159
+
160
+ return CopyToClipboard(
161
+ text_to_copy=df.slice(offset=0, length=max_rows).__repr__(),
162
+ )
@@ -1,11 +1,13 @@
1
1
  """
2
2
  A collection of polars expressions/idioms.
3
3
 
4
- These expressions have an unstable API and will change over time. Use
5
- them as a template and vendor within your own codebase for stability.
6
- These probably belong in a docs page, but they have earned their place
7
- here due to their widespread use across multiple domains. most of them
8
- are scavenged from Stackoverflow, Discord and github issues.
4
+ These helpers could probably be snippets in a docs page. But they have
5
+ earned their place here due to their utility across different domains.
6
+ Most of these are slight modifications of snippets scavenged across the
7
+ internet (primarily Stackoverflow, Discord and Github) and I have
8
+ attempted to credit the original sources wherever possible. You can use
9
+ them as a template or building blocks for complex data processing
10
+ pipelines.
9
11
  """
10
12
 
11
13
  import re
@@ -29,6 +31,16 @@ _COL_RE = re.compile(
29
31
  re.VERBOSE,
30
32
  )
31
33
 
34
+ __all__ = [
35
+ "all_minmax_by",
36
+ "item_where",
37
+ "ksigma_bounds",
38
+ "list_cast",
39
+ "list_render_unique",
40
+ "minmax",
41
+ "spec",
42
+ ]
43
+
32
44
 
33
45
  def minmax(
34
46
  expr: pl.Expr,
@@ -422,8 +434,9 @@ def spec(
422
434
  operator, *vals = spec.split()
423
435
  try:
424
436
  vals = [_parse_operand(v) for v in vals]
425
- except InvalidNumber:
426
- raise ValueError(f"bad numbers {vals} in spec: {spec}")
437
+ except InvalidNumber as err:
438
+ err_msg = f"bad numbers {vals} in spec: {spec}"
439
+ raise ValueError(err_msg) from err
427
440
 
428
441
  match operator:
429
442
  case ">":
@@ -437,10 +450,55 @@ def spec(
437
450
  val, tol_pct = vals
438
451
  tol_abs = abs(val) * tol_pct / 100
439
452
  return col.is_between(val - tol_abs, val + tol_abs)
440
- raise ValueError(f"bad spec: {spec}")
453
+ err_msg = f"Improperly formatted spec: {spec}"
454
+ raise ValueError(err_msg)
455
+
441
456
 
457
+ def list_cast() -> tuple[pl.Expr, pl.Expr]:
458
+ """
459
+ Cast list columns to list[str]
442
460
 
443
- def list_cast():
461
+ Uses ``render`` to convert numeric values and casts categorical
462
+ values to string.
463
+
464
+ Returns
465
+ -------
466
+ tuple[pl.Expr, pl.Expr]
467
+
468
+ Examples
469
+ --------
470
+ >>> (
471
+ ... df := pl.DataFrame(
472
+ ... {"a": [[1000, 2.5e-6]], "b": [["x", "y"]]},
473
+ ... schema={
474
+ ... "a": pl.List(pl.Float64),
475
+ ... "b": pl.List(pl.Categorical),
476
+ ... },
477
+ ... )
478
+ ... )
479
+ shape: (1, 2)
480
+ ┌─────────────────────┬────────────┐
481
+ │ a ┆ b │
482
+ │ --- ┆ --- │
483
+ │ list[f64] ┆ list[cat] │
484
+ ╞═════════════════════╪════════════╡
485
+ │ [1000.0, 0.0000025] ┆ ["x", "y"] │
486
+ └─────────────────────┴────────────┘
487
+ >>> out = df.with_columns(*list_cast())
488
+ >>> out
489
+ shape: (1, 2)
490
+ ┌────────────────┬────────────┐
491
+ │ a ┆ b │
492
+ │ --- ┆ --- │
493
+ │ list[str] ┆ list[str] │
494
+ ╞════════════════╪════════════╡
495
+ │ ["1k", "2.5u"] ┆ ["x", "y"] │
496
+ └────────────────┴────────────┘
497
+ >>> out.schema.contains_dtype(pl.String, recursive=True)
498
+ True
499
+ >>> out.schema.contains_dtype(pl.Categorical, recursive=True)
500
+ False
501
+ """
444
502
  return (
445
503
  cs.list(cs.numeric()).list.eval(
446
504
  pl.element().map_elements(
@@ -452,13 +510,47 @@ def list_cast():
452
510
  )
453
511
 
454
512
 
455
- def list_render_unique(max_len: int = 3):
513
+ def list_render_unique(max_len: int = 3) -> pl.Expr:
514
+ """
515
+ Render unique values of list[str] columns as a comma-joined string.
516
+
517
+ Lists with more than ``max_len`` unique values are truncated and
518
+ suffixed with the count of omitted values. The ordering is not
519
+ deterministic since ``pl.Expr.unique`` doesn't maintain order.
520
+
521
+ Parameters
522
+ ----------
523
+ max_len : int, default=3
524
+ Maximum number of unique values to show before truncating.
525
+
526
+ Returns
527
+ -------
528
+ pl.Expr
529
+ Expression (over all list[str] columns) yielding a string.
530
+
531
+ Examples
532
+ --------
533
+ >>> (df := pl.DataFrame({"a": [["x", "x"], ["a", "b", "c", "d", "e"]]}))
534
+ shape: (2, 1)
535
+ ┌───────────────────┐
536
+ │ a │
537
+ │ --- │
538
+ │ list[str] │
539
+ ╞═══════════════════╡
540
+ │ ["x", "x"] │
541
+ │ ["a", "b", … "e"] │
542
+ └───────────────────┘
543
+ >>> out = df.select(list_render_unique(max_len=3))["a"].to_list()
544
+ >>> out[0]
545
+ 'x'
546
+ >>> out[1].endswith(" + 2 more")
547
+ True
548
+ """
456
549
  ulist = cs.list(cs.string()).list.unique().list
457
550
  n = ulist.len()
458
551
  head_n = ulist.head(max_len).list
459
- cond = (
552
+ return (
460
553
  pl.when(n > max_len)
461
554
  .then(pl.format("{} + {} more", head_n.join(", "), n - max_len))
462
555
  .otherwise(ulist.join(", "))
463
556
  )
464
- return cond