spells-mtg 0.9.8__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/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.8
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
@@ -11,8 +11,9 @@ spells/filter.py,sha256=J-YTOOAzOQpvIX29tviYL04RVoOUlfsbjBXoQBDCEdQ,3380
11
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.8.dist-info/METADATA,sha256=TApjATiI8kkKGHCEEEFNhKdmtxUENMD-Qr1VLtDqMic,47007
15
- spells_mtg-0.9.8.dist-info/WHEEL,sha256=thaaA2w1JzcGC48WYufAs8nrYZjJm8LqNfnXFOFyCC4,90
16
- spells_mtg-0.9.8.dist-info/entry_points.txt,sha256=a9Y1omdl9MdnKuIj3aOodgrp-zZII6OCdvqwgP6BFvI,63
17
- spells_mtg-0.9.8.dist-info/licenses/LICENSE,sha256=tS54XYbJSgmq5zuHhbsQGbNQLJPVgXqhF5nu2CSRMig,1068
18
- spells_mtg-0.9.8.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,,