spells-mtg 0.9.7__py3-none-any.whl → 0.10.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.

Potentially problematic release.


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

spells/config.py CHANGED
@@ -11,6 +11,7 @@ all_sets = [
11
11
  "WOE",
12
12
  "LTR",
13
13
  "MOM",
14
+ "SIR",
14
15
  "ONE",
15
16
  "BRO",
16
17
  "DMU",
spells/log.py CHANGED
@@ -63,10 +63,12 @@ def console_logging(log_level):
63
63
  logger.removeHandler(console_handler)
64
64
 
65
65
 
66
- def make_verbose(level: int = logging.ERROR) -> Callable:
66
+ def make_verbose(level: int | None = None) -> Callable:
67
67
  def decorator(func: Callable) -> Callable:
68
68
  @wraps(func)
69
- def wrapped(*args, log_to_console: int = level, **kwargs):
69
+ def wrapped(*args, log_to_console: int | None = level, **kwargs):
70
+ if log_to_console is None:
71
+ return func(*args, **kwargs)
70
72
  with console_logging(log_to_console):
71
73
  return func(*args, **kwargs)
72
74
 
spells/utils.py ADDED
@@ -0,0 +1,55 @@
1
+ import polars as pl
2
+
3
+ def convert_to_expr_list(
4
+ input: str | pl.Expr | list[str | pl.Expr] | None
5
+ ):
6
+ if input is None:
7
+ return []
8
+
9
+ input_list = [input] if isinstance(input, str | pl.Expr) else input
10
+ return [pl.col(i) if isinstance(i, str) else i for i in input_list]
11
+
12
+
13
+ def wavg(
14
+ df: pl.DataFrame,
15
+ cols: str | pl.Expr | list[str | pl.Expr],
16
+ weights: str | pl.Expr | list[str | pl.Expr],
17
+ group_by: str | pl.Expr | list[str | pl.Expr] | None = None,
18
+ new_names: str | list[str] | None = None,
19
+ ) -> pl.DataFrame:
20
+ col_list = convert_to_expr_list(cols)
21
+ weight_list = convert_to_expr_list(weights)
22
+ gbs = convert_to_expr_list(group_by)
23
+
24
+ name_list: list[str]
25
+ if isinstance(new_names, str):
26
+ name_list = [new_names]
27
+ elif new_names is None:
28
+ name_list = [c.meta.output_name() for c in col_list]
29
+ else:
30
+ name_list = list(new_names)
31
+
32
+ assert len(name_list) == len(col_list), f"{len(name_list)} names provided for {len(col_list)} columns"
33
+ assert len(name_list) == len(set(name_list)), "Output names must be unique"
34
+ assert len(weight_list) == len(col_list) or len(weight_list) == 1, f"{len(weight_list)} weights provided for {len(col_list)} columns"
35
+
36
+ enum_wl = weight_list * int(len(col_list) / len(weight_list))
37
+ wl_names = [w.meta.output_name() for w in weight_list]
38
+ assert len(wl_names) == len(set(wl_names)), "Weights must have unique names. Send one weight column or n uniquely named ones"
39
+
40
+ to_group = df.select(gbs + weight_list + [
41
+ (c * enum_wl[i]).alias(name_list[i]) for i, c in enumerate(col_list)
42
+ ])
43
+
44
+ grouped = to_group if not gbs else to_group.group_by(gbs)
45
+
46
+ ret_df = grouped.sum().select(
47
+ gbs +
48
+ wl_names +
49
+ [(pl.col(name) / pl.col(enum_wl[i].meta.output_name())) for i, name in enumerate(name_list)]
50
+ )
51
+
52
+ if gbs:
53
+ ret_df = ret_df.sort(by=gbs)
54
+
55
+ return ret_df
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spells-mtg
3
- Version: 0.9.7
3
+ Version: 0.10.0
4
4
  Summary: analaysis of 17Lands.com public datasets
5
5
  Author-Email: Joel Barnes <oelarnes@gmail.com>
6
6
  License: MIT
@@ -2,17 +2,18 @@ spells/__init__.py,sha256=0pnh2NLn9FrNKncE9-tBsighp3e8YAsN--_ovUpgWGs,333
2
2
  spells/cache.py,sha256=7XDcltmlpagK2nkhuCCcAQVyrFMYkw9Acr7iVsLs3JU,3799
3
3
  spells/cards.py,sha256=uYOnFXroAuUpMB0NuuBcAZ1n5OtNTQyq1mvK3ctls6Q,3710
4
4
  spells/columns.py,sha256=PztPNLtqKIqIQdiCHYykk7bcYlx0_QRypu3WOsSZb-A,17856
5
- spells/config.py,sha256=4Q4F_wNsjXjWONA5uLn_Xu2xPoNm0vcPGqNHWd7khIk,202
5
+ spells/config.py,sha256=_t98dc_uY3Wp3d5tsU3CJgVcWOD3wVlwMo98-tN2KRY,213
6
6
  spells/draft_data.py,sha256=DpbKEcv-tTCJ1-R9-_lS-H8oejYl-2OEcUDSUDsRtJI,19626
7
7
  spells/enums.py,sha256=DL7e1xDEvrsTMbA7vJB_Et1DaYkyO4rIEzvIQDz3MZk,4871
8
8
  spells/extension.py,sha256=DVzIedggeGfkD6BD5g-dko9l9BoPgmXWvcQ3NWdEG0U,6991
9
9
  spells/external.py,sha256=ukcEWiu6aLJYJgQlRMAH6EmdZ2OZUFPEr54KdWnR5ug,11510
10
10
  spells/filter.py,sha256=J-YTOOAzOQpvIX29tviYL04RVoOUlfsbjBXoQBDCEdQ,3380
11
- spells/log.py,sha256=_yQjVge-krVtom7CfTmgv_oc78jnt5NDKElTBgdqdfE,2086
11
+ spells/log.py,sha256=3avmg65hru8K9npKLvPp1wWWxq-hoEYDUCbxqhPkKUw,2175
12
12
  spells/manifest.py,sha256=dOUmj2uZZ17vCWpFwv7B5F6wOIWnoQdZkEB9SDKdx9M,8310
13
13
  spells/schema.py,sha256=DbMvV8PIThJTp0Xzp_XIorlW6JhE1ud1kWRGf5SQ4_c,6406
14
- spells_mtg-0.9.7.dist-info/METADATA,sha256=jP7n_UCl7q2Ude2HClulr4ZsJhLJF1rVd5xwiL5HDIU,47007
15
- spells_mtg-0.9.7.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
16
- spells_mtg-0.9.7.dist-info/entry_points.txt,sha256=a9Y1omdl9MdnKuIj3aOodgrp-zZII6OCdvqwgP6BFvI,63
17
- spells_mtg-0.9.7.dist-info/licenses/LICENSE,sha256=tS54XYbJSgmq5zuHhbsQGbNQLJPVgXqhF5nu2CSRMig,1068
18
- spells_mtg-0.9.7.dist-info/RECORD,,
14
+ spells/utils.py,sha256=IO3brrXVvZla0LRTEB5v6NgGqZb_rYA46XtKBURGMNk,1944
15
+ spells_mtg-0.10.0.dist-info/METADATA,sha256=Uj4GOhiHcGnWlI31o52ZGZ8PnnZGJggw81N558btGPE,47008
16
+ spells_mtg-0.10.0.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
17
+ spells_mtg-0.10.0.dist-info/entry_points.txt,sha256=a9Y1omdl9MdnKuIj3aOodgrp-zZII6OCdvqwgP6BFvI,63
18
+ spells_mtg-0.10.0.dist-info/licenses/LICENSE,sha256=tS54XYbJSgmq5zuHhbsQGbNQLJPVgXqhF5nu2CSRMig,1068
19
+ spells_mtg-0.10.0.dist-info/RECORD,,