mergeron 2024.738949.1__py3-none-any.whl → 2024.738949.6__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 mergeron might be problematic. Click here for more details.

mergeron/__init__.py CHANGED
@@ -1,3 +1,6 @@
1
+ from __future__ import annotations
2
+
3
+ import enum
1
4
  from importlib.metadata import version
2
5
  from pathlib import Path
3
6
 
@@ -14,3 +17,29 @@ If the subdirectory doesn't exist, it is created on package invocation.
14
17
 
15
18
  if not DATA_DIR.is_dir():
16
19
  DATA_DIR.mkdir(parents=False)
20
+
21
+
22
+ @enum.unique
23
+ class RECConstants(enum.StrEnum):
24
+ """Recapture rate - derivation methods."""
25
+
26
+ INOUT = "inside-out"
27
+ OUTIN = "outside-in"
28
+ FIXED = "proportional"
29
+
30
+
31
+ @enum.unique
32
+ class UPPAggrSelector(enum.Enum):
33
+ """
34
+ Aggregator selection for GUPPI and diversion ratio
35
+
36
+ """
37
+
38
+ AVG = "average"
39
+ CPA = "cross-product-share weighted average"
40
+ CPD = "cross-product-share weighted distance"
41
+ DIS = "symmetrically-weighted distance"
42
+ MAX = "max"
43
+ MIN = "min"
44
+ OSA = "own-share weighted average"
45
+ OSD = "own-share weighted distance"
mergeron/core/__init__.py CHANGED
@@ -1,5 +1,69 @@
1
+ from __future__ import annotations
2
+
1
3
  from importlib.metadata import version
4
+ from multiprocessing import Value
5
+
6
+ from attrs import Attribute, define, field, validators
2
7
 
3
- from .. import _PKG_NAME # noqa: TID252
8
+ from .. import _PKG_NAME, RECConstants, UPPAggrSelector # noqa: TID252
4
9
 
5
10
  __version__ = version(_PKG_NAME)
11
+
12
+
13
+ def _delta_value_validator(
14
+ _instance: UPPBoundarySpec, _attribute: Attribute[float], _value: float, /
15
+ ) -> None:
16
+ if not 0 <= _value <= 1:
17
+ raise ValueError(
18
+ "Margin-adjusted benchmark share ratio must lie between 0 and 1."
19
+ )
20
+
21
+
22
+ def _rec_spec_validator(
23
+ _instance: UPPBoundarySpec,
24
+ _attribute: Attribute[RECConstants],
25
+ _value: RECConstants,
26
+ /,
27
+ ) -> None:
28
+ if _value == RECConstants.OUTIN:
29
+ raise ValueError(
30
+ f"Invalid recapture specification, {_value!r}. "
31
+ "You may consider specifying RECConstants.INOUT here, and "
32
+ "assigning the recapture rate for the merging-firm with "
33
+ 'the smaller market-share to the attribue, "rec" of '
34
+ "the UPPBoundarySpec object you pass."
35
+ )
36
+ if _value is None and _instance.agg_method != UPPAggrSelector.MAX:
37
+ raise ValueError(
38
+ f"Specified aggregation method, {_instance.agg_method} requires a recapture specification."
39
+ )
40
+
41
+
42
+ @define(slots=True, frozen=True)
43
+ class UPPBoundarySpec:
44
+ share_ratio: float = field(
45
+ kw_only=False,
46
+ default=0.075,
47
+ validator=(validators.instance_of(float), _delta_value_validator),
48
+ )
49
+ rec: float = field(
50
+ kw_only=False, default=0.80, validator=validators.instance_of(float)
51
+ )
52
+
53
+ agg_method: UPPAggrSelector = field(
54
+ kw_only=True,
55
+ default=UPPAggrSelector.MAX,
56
+ validator=validators.instance_of(UPPAggrSelector),
57
+ )
58
+ recapture_spec: RECConstants | None = field(
59
+ kw_only=True,
60
+ default=RECConstants.INOUT,
61
+ validator=(
62
+ validators.optional(validators.instance_of(RECConstants)), # type: ignore
63
+ _rec_spec_validator,
64
+ ),
65
+ )
66
+
67
+ precision: int = field(
68
+ kw_only=False, default=5, validator=validators.instance_of(int)
69
+ )
@@ -24,18 +24,11 @@ __version__ = version(_PKG_NAME)
24
24
 
25
25
 
26
26
  @enum.unique
27
- class CFmtParent(dict[str, Any], enum.ReprEnum):
28
- def merge(self, _other) -> CFmtParent:
29
- if isinstance(_other, CFmtParent):
30
- return self.value | _other.value
31
- else:
32
- raise RuntimeWarning(
33
- f"Object {_other!r} not valid for merge(), returned original."
34
- )
35
- return self.value
27
+ class CFmtParent(dict[str, Any], enum.ReprEnum): # type: ignore
28
+ """Unique mappings defining xlsxwirter Workbook formats"""
36
29
 
37
30
 
38
- class CFmt(CFmtParent): # type: ignore
31
+ class CFmt(CFmtParent):
39
32
  """
40
33
  Initialize cell formats for xlsxwriter.
41
34
 
@@ -140,7 +133,7 @@ def matrix_to_sheet(
140
133
  elif isinstance(cell_format, CFmt):
141
134
  _cell_format = (cell_format,) * len(_data_array[0])
142
135
  else:
143
- _cell_format = (CFmt.XL_DEFAULT,) * len(_data_array[0]) # type: ignore
136
+ _cell_format = (CFmt.XL_DEFAULT,) * len(_data_array[0])
144
137
 
145
138
  for _cell_row in range(_row_id, _bottom_row_id):
146
139
  for _cell_col in range(_col_id, _right_column_id):
@@ -236,7 +229,7 @@ def xl_fmt(
236
229
  elif isinstance(_cell_fmt, CFmt):
237
230
  _cell_fmt_dict = _cell_fmt.value
238
231
  else:
239
- _cell_fmt_dict = CFmt.XL_DEFAULT.value # type: ignore
232
+ _cell_fmt_dict = CFmt.XL_DEFAULT.value
240
233
 
241
234
  return _xl_book.add_format(_cell_fmt_dict)
242
235