spells-mtg 0.7.4__tar.gz → 0.8.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.

Potentially problematic release.


This version of spells-mtg might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spells-mtg
3
- Version: 0.7.4
3
+ Version: 0.8.1
4
4
  Summary: analaysis of 17Lands.com public datasets
5
5
  Author-Email: Joel Barnes <oelarnes@gmail.com>
6
6
  License: MIT
@@ -11,7 +11,7 @@ dependencies = [
11
11
  ]
12
12
  requires-python = ">=3.11"
13
13
  readme = "README.md"
14
- version = "0.7.4"
14
+ version = "0.8.1"
15
15
 
16
16
  [project.license]
17
17
  text = "MIT"
@@ -0,0 +1,5 @@
1
+ from spells.columns import ColSpec
2
+ from spells.enums import ColType, ColName
3
+ from spells.draft_data import summon, view_select, get_names
4
+
5
+ __all__ = ["summon", "view_select", "get_names", "ColSpec", "ColType", "ColName"]
@@ -25,6 +25,8 @@ class ColDef:
25
25
 
26
26
 
27
27
  default_columns = [
28
+ ColName.COLOR,
29
+ ColName.RARITY,
28
30
  ColName.NUM_SEEN,
29
31
  ColName.ALSA,
30
32
  ColName.NUM_TAKEN,
@@ -35,7 +35,7 @@ def _cache_key(args) -> str:
35
35
 
36
36
 
37
37
  @functools.lru_cache(maxsize=None)
38
- def _get_names(set_code: str) -> list[str]:
38
+ def get_names(set_code: str) -> list[str]:
39
39
  card_fp = data_file_path(set_code, View.CARD)
40
40
  card_view = pl.read_parquet(card_fp)
41
41
  card_names_set = frozenset(card_view.get_column("name").to_list())
@@ -86,7 +86,7 @@ def _get_card_context(
86
86
 
87
87
  loaded_context = {row[ColName.NAME]: row for row in select_rows}
88
88
  else:
89
- names = _get_names(set_code)
89
+ names = get_names(set_code)
90
90
  loaded_context = {name: {} for name in names}
91
91
 
92
92
  if card_context is not None:
@@ -265,7 +265,7 @@ def _hydrate_col_defs(
265
265
  set_context: pl.DataFrame | dict[str, Any] | None = None,
266
266
  card_only: bool = False,
267
267
  ):
268
- names = _get_names(set_code)
268
+ names = get_names(set_code)
269
269
 
270
270
  set_context = _get_set_context(set_code, set_context)
271
271
 
@@ -538,7 +538,14 @@ def summon(
538
538
  ), "What happened? We mean to use one of the sets manifest, it shouldn't matter which."
539
539
 
540
540
  if m.group_by:
541
- full_agg_df = full_agg_df.group_by(m.group_by).sum()
541
+ gb = m.group_by
542
+ # an agg may depend on some card column that hasn't been explicitly requested, but can be safely
543
+ # depended on if we are grouping by name
544
+ if ColName.NAME in m.group_by and View.CARD in m.view_cols:
545
+ for col in m.view_cols[View.CARD]:
546
+ if col not in m.group_by:
547
+ gb = tuple([*gb, col])
548
+ full_agg_df = full_agg_df.group_by(gb).sum()
542
549
  else:
543
550
  full_agg_df = full_agg_df.sum()
544
551
 
@@ -550,3 +557,46 @@ def summon(
550
557
  )
551
558
 
552
559
  return ret_df
560
+
561
+
562
+ def view_select(
563
+ set_code: str,
564
+ view: View,
565
+ columns: list[str],
566
+ filter_spec: dict | None = None,
567
+ extensions: dict[str, ColSpec] | list[dict[str, ColSpec]] | None = None,
568
+ card_context: dict | pl.DataFrame | None = None,
569
+ set_context: dict | pl.DataFrame | None = None,
570
+ ) -> pl.LazyFrame:
571
+ specs = get_specs()
572
+
573
+ if extensions is not None:
574
+ if not isinstance(extensions, list):
575
+ extensions = [extensions]
576
+ for ext in extensions:
577
+ specs.update(ext)
578
+
579
+ col_def_map = _hydrate_col_defs(set_code, specs, card_context, set_context)
580
+
581
+ df_path = data_file_path(set_code, view)
582
+ base_view_df = pl.scan_parquet(df_path)
583
+
584
+ select_cols = frozenset(columns)
585
+
586
+ filter_ = spells.filter.from_spec(filter_spec)
587
+ if filter_ is not None:
588
+ select_cols = select_cols.union(filter_.lhs)
589
+
590
+ base_df_prefilter = _view_select(
591
+ base_view_df,
592
+ select_cols,
593
+ col_def_map,
594
+ is_agg_view=False,
595
+ )
596
+
597
+ if filter_ is not None:
598
+ base_df = base_df_prefilter.filter(filter_.expr)
599
+ else:
600
+ base_df = base_df_prefilter
601
+
602
+ return base_df.select(columns)
@@ -163,14 +163,14 @@ def create(
163
163
  group_by: list[str] | None = None,
164
164
  filter_spec: dict | None = None,
165
165
  ):
166
- gbs = (
167
- (ColName.NAME, ColName.COLOR, ColName.RARITY)
168
- if group_by is None
169
- else tuple(group_by)
170
- )
166
+ gbs = (ColName.NAME,) if group_by is None else tuple(group_by)
171
167
 
172
168
  if columns is None:
173
169
  cols = tuple(spells.columns.default_columns)
170
+ if ColName.NAME not in gbs:
171
+ cols = tuple(
172
+ col for col in cols if col not in (ColName.COLOR, ColName.RARITY)
173
+ )
174
174
  else:
175
175
  cols = tuple(columns)
176
176
 
@@ -1,5 +0,0 @@
1
- from spells.columns import ColSpec
2
- from spells.enums import ColType, ColName
3
- from spells.draft_data import summon
4
-
5
- __all__ = ["summon", "ColSpec", "ColType", "ColName"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes