sdvplot 0.1.0__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.
Files changed (49) hide show
  1. sdvplot/__init__.py +68 -0
  2. sdvplot/_cache.py +484 -0
  3. sdvplot/_colors.py +206 -0
  4. sdvplot/_contrast.py +60 -0
  5. sdvplot/_court.py +110 -0
  6. sdvplot/_deprecate.py +39 -0
  7. sdvplot/_dispatch.py +342 -0
  8. sdvplot/_errors.py +93 -0
  9. sdvplot/_headshots.py +131 -0
  10. sdvplot/_images.py +292 -0
  11. sdvplot/_index.py +178 -0
  12. sdvplot/_lazy.py +15 -0
  13. sdvplot/_manifest.py +73 -0
  14. sdvplot/_marks.py +296 -0
  15. sdvplot/_normalize.py +82 -0
  16. sdvplot/_placement.py +168 -0
  17. sdvplot/_resolve.py +363 -0
  18. sdvplot/_surface.py +220 -0
  19. sdvplot/_tables.py +87 -0
  20. sdvplot/_tiers.py +135 -0
  21. sdvplot/_types.py +38 -0
  22. sdvplot/_versions.py +30 -0
  23. sdvplot/_web.py +61 -0
  24. sdvplot/altair.py +652 -0
  25. sdvplot/bokeh.py +323 -0
  26. sdvplot/data/INDEX_VERSION +1 -0
  27. sdvplot/data/aliases.parquet +0 -0
  28. sdvplot/data/teams.parquet +0 -0
  29. sdvplot/folium.py +316 -0
  30. sdvplot/great_tables/__init__.py +267 -0
  31. sdvplot/great_tables/_cells.py +1814 -0
  32. sdvplot/great_tables/_export.py +844 -0
  33. sdvplot/great_tables/_layout.py +1802 -0
  34. sdvplot/great_tables/_marks.py +798 -0
  35. sdvplot/great_tables/_themes.py +2134 -0
  36. sdvplot/holoviews.py +303 -0
  37. sdvplot/matplotlib.py +934 -0
  38. sdvplot/plotly.py +595 -0
  39. sdvplot/plotnine.py +1104 -0
  40. sdvplot/plottable.py +141 -0
  41. sdvplot/py.typed +0 -0
  42. sdvplot/pygal.py +416 -0
  43. sdvplot/reactable.py +488 -0
  44. sdvplot/testing.py +579 -0
  45. sdvplot/typing.py +21 -0
  46. sdvplot-0.1.0.dist-info/METADATA +188 -0
  47. sdvplot-0.1.0.dist-info/RECORD +49 -0
  48. sdvplot-0.1.0.dist-info/WHEEL +4 -0
  49. sdvplot-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,267 @@
1
+ """great_tables helpers (``pip install sdvplot[tables]``), ported from sdvplotR's ``gt_*`` functions.
2
+
3
+ Team logos, wordmarks and headshots in cells and column labels, team-colored text, and the SportsDataverse themes.
4
+ Heights are pixels: a table has no plot height.
5
+
6
+ sdvplot's front door routes a ``GT`` here: ``sdvplot.add_logos(gt, "team", league="nfl")`` is ``gt_sdv_logos``
7
+ (``add_wordmarks`` and ``add_headshots`` likewise), and ``axis_logos`` raises TypeError (a table has no axes).
8
+
9
+ Test hooks for ``sdvplot.testing.check_table_adapter_contract``: ``_rendered_html(gt)`` and ``_drawn_cells(gt)``.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import math
15
+ import re
16
+ from html.parser import HTMLParser
17
+ from typing import Any
18
+
19
+ from sdvplot._errors import UnsupportedTargetError, requires_extra
20
+
21
+ with requires_extra("tables"):
22
+ from great_tables import GT
23
+
24
+ from sdvplot.great_tables._cells import (
25
+ gt_538_caption,
26
+ gt_bold_rows,
27
+ gt_border_bars_bottom,
28
+ gt_border_bars_top,
29
+ gt_border_grid,
30
+ gt_color_pills,
31
+ gt_color_ranks,
32
+ gt_color_results,
33
+ gt_column_subheaders,
34
+ gt_cutline,
35
+ gt_delta,
36
+ gt_fmt_rank,
37
+ gt_fmt_tally,
38
+ gt_group_stripes,
39
+ gt_highlight_cells,
40
+ gt_highlight_na,
41
+ gt_indicator_boxes,
42
+ )
43
+ from sdvplot.great_tables._export import gt_grid, gt_save_batch, gt_save_crop, gt_social_crop, gt_stack_tables
44
+ from sdvplot.great_tables._layout import (
45
+ gt_legend_continuous,
46
+ gt_legend_discrete,
47
+ gt_marginalia,
48
+ gt_outliers,
49
+ gt_percentile_bar,
50
+ gt_row_accent,
51
+ gt_scale_note,
52
+ gt_set_font,
53
+ gt_significance,
54
+ gt_snake,
55
+ gt_snake_align,
56
+ gt_social_tag,
57
+ gt_spotlight,
58
+ gt_tiers,
59
+ gt_title_header,
60
+ gt_watermark,
61
+ gt_wrap_labels,
62
+ )
63
+ from sdvplot.great_tables._marks import (
64
+ gt_merge_stack_team_color,
65
+ gt_sdv_cols_label,
66
+ gt_sdv_headshots,
67
+ gt_sdv_logos,
68
+ gt_sdv_wordmarks,
69
+ gt_theme_sdv,
70
+ gt_theme_sdv_team,
71
+ )
72
+ from sdvplot.great_tables._themes import (
73
+ gt_theme_almanac,
74
+ gt_theme_athletic,
75
+ gt_theme_booktabs,
76
+ gt_theme_broadsheet,
77
+ gt_theme_brutalist,
78
+ gt_theme_drench,
79
+ gt_theme_gtutils,
80
+ gt_theme_kenpom,
81
+ gt_theme_midnight,
82
+ gt_theme_ncaa,
83
+ gt_theme_pl,
84
+ gt_theme_preview,
85
+ gt_theme_savant,
86
+ gt_theme_scoreboard,
87
+ gt_theme_sofa,
88
+ gt_theme_swiss,
89
+ gt_theme_terminal,
90
+ gt_theme_tier,
91
+ gt_theme_tufte,
92
+ pal_midnight,
93
+ )
94
+
95
+ _SUPPORTS_AXIS_LOGOS = False
96
+ add_logos = gt_sdv_logos
97
+ add_wordmarks = gt_sdv_wordmarks
98
+ add_headshots = gt_sdv_headshots
99
+
100
+
101
+ def axis_logos(target: Any, *args: Any, **kwargs: Any) -> Any:
102
+ """A table has no axes, so this always raises; ``gt_sdv_cols_label`` puts marks in the column labels instead.
103
+
104
+ Args:
105
+ target: A ``great_tables.GT``.
106
+ *args: Ignored.
107
+ **kwargs: Ignored.
108
+
109
+ Returns:
110
+ object: Never returns.
111
+
112
+ Raises:
113
+ UnsupportedTargetError: Always (a ``TypeError``).
114
+
115
+ Example:
116
+ ::
117
+
118
+ import polars as pl
119
+ from great_tables import GT
120
+ import sdvplot
121
+
122
+ gt = GT(pl.DataFrame({"team": ["KC", "BUF"], "wins": [12, 10]}))
123
+ try:
124
+ sdvplot.axis_logos(gt, "team", league="nfl")
125
+ except TypeError:
126
+ pass # raised: a table has no axes
127
+
128
+ See Also:
129
+ sdvplotR element_sdv_logo(): https://sdvplotR.sportsdataverse.org/ ;
130
+ sdvplot.great_tables.gt_sdv_cols_label: marks in the column labels
131
+ """
132
+ raise UnsupportedTargetError(
133
+ "a great_tables table has no axes; use gt_sdv_cols_label() for marks in the column labels"
134
+ )
135
+
136
+
137
+ def _rendered_html(gt: GT) -> str:
138
+ """The table as great_tables renders it (``as_raw_html()``)."""
139
+ return gt.as_raw_html()
140
+
141
+
142
+ _HEIGHT = re.compile(r"height:\s*([0-9.]+)px")
143
+
144
+
145
+ class _Cells(HTMLParser):
146
+ """Collects the sdvplot images of a rendered table: column-label images (row -1) and body-cell images."""
147
+
148
+ def __init__(self) -> None:
149
+ super().__init__()
150
+ self.section = ""
151
+ self.columns: list[str] = [] # the column-label ids, left to right (the stub's is "")
152
+ self.label = "" # the id of the column label being read
153
+ self.row = -1
154
+ self.col = -1
155
+ self.cells: list[tuple[str, int, str, float, str]] = []
156
+
157
+ def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None:
158
+ a = {k: v or "" for k, v in attrs}
159
+ classes = a.get("class", "").split()
160
+ if tag in ("thead", "tbody"):
161
+ self.section = tag
162
+ elif tag == "tr" and self.section == "tbody":
163
+ self.col = -1
164
+ if "gt_group_heading_row" not in classes:
165
+ self.row += 1
166
+ elif tag == "th" and a.get("scope") == "col":
167
+ self.label = a.get("id", "")
168
+ self.columns.append(self.label)
169
+ elif tag in ("td", "th") and "gt_row" in classes:
170
+ self.col += 1
171
+ elif tag == "img" and "data-sdvplot-team" in a:
172
+ m = _HEIGHT.search(a.get("style", ""))
173
+ h = float(m.group(1)) if m else math.nan
174
+ team, src = a["data-sdvplot-team"], a.get("src", "")
175
+ if self.section == "thead":
176
+ self.cells.append((team, -1, self.label, h, src))
177
+ elif self.section == "tbody" and self.col >= 0:
178
+ self.cells.append((team, self.row, self.columns[self.col], h, src))
179
+
180
+
181
+ def _drawn_cells(gt: GT) -> list[tuple[str, int, str, float, str]]:
182
+ """``(team_id, row, column, height_px, src)`` per sdvplot image in the rendered table, in display order.
183
+
184
+ Body images carry their display row (0-based, group headings not counted) and column name; column-label images
185
+ carry row -1. Images in row-group headings are not listed. Tables with column spanners are not supported.
186
+ """
187
+ parser = _Cells()
188
+ parser.feed(_rendered_html(gt))
189
+ return parser.cells
190
+
191
+
192
+ __all__ = [
193
+ "add_headshots",
194
+ "add_logos",
195
+ "add_wordmarks",
196
+ "axis_logos",
197
+ "gt_538_caption",
198
+ "gt_bold_rows",
199
+ "gt_border_bars_bottom",
200
+ "gt_border_bars_top",
201
+ "gt_border_grid",
202
+ "gt_color_pills",
203
+ "gt_color_ranks",
204
+ "gt_color_results",
205
+ "gt_column_subheaders",
206
+ "gt_cutline",
207
+ "gt_delta",
208
+ "gt_fmt_rank",
209
+ "gt_fmt_tally",
210
+ "gt_grid",
211
+ "gt_group_stripes",
212
+ "gt_highlight_cells",
213
+ "gt_highlight_na",
214
+ "gt_indicator_boxes",
215
+ "gt_legend_continuous",
216
+ "gt_legend_discrete",
217
+ "gt_marginalia",
218
+ "gt_merge_stack_team_color",
219
+ "gt_outliers",
220
+ "gt_percentile_bar",
221
+ "gt_row_accent",
222
+ "gt_save_batch",
223
+ "gt_save_crop",
224
+ "gt_scale_note",
225
+ "gt_sdv_cols_label",
226
+ "gt_sdv_headshots",
227
+ "gt_sdv_logos",
228
+ "gt_sdv_wordmarks",
229
+ "gt_set_font",
230
+ "gt_significance",
231
+ "gt_snake",
232
+ "gt_snake_align",
233
+ "gt_social_crop",
234
+ "gt_social_tag",
235
+ "gt_spotlight",
236
+ "gt_stack_tables",
237
+ "gt_theme_almanac",
238
+ "gt_theme_athletic",
239
+ "gt_theme_booktabs",
240
+ "gt_theme_broadsheet",
241
+ "gt_theme_brutalist",
242
+ "gt_theme_drench",
243
+ "gt_theme_gtutils",
244
+ "gt_theme_kenpom",
245
+ "gt_theme_midnight",
246
+ "gt_theme_ncaa",
247
+ "gt_theme_pl",
248
+ "gt_theme_preview",
249
+ "gt_theme_savant",
250
+ "gt_theme_scoreboard",
251
+ "gt_theme_sdv",
252
+ "gt_theme_sdv_team",
253
+ "gt_theme_sofa",
254
+ "gt_theme_swiss",
255
+ "gt_theme_terminal",
256
+ "gt_theme_tier",
257
+ "gt_theme_tufte",
258
+ "gt_tiers",
259
+ "gt_title_header",
260
+ "gt_watermark",
261
+ "gt_wrap_labels",
262
+ "pal_midnight",
263
+ ]
264
+
265
+
266
+ def __dir__() -> list[str]: # dir() and tab completion show the public API only
267
+ return list(__all__)