mergeron 2024.739125.3__py3-none-any.whl → 2024.739127.1__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
@@ -2,14 +2,13 @@ from __future__ import annotations
2
2
 
3
3
  import enum
4
4
  from pathlib import Path
5
- from typing import TypeAlias
6
5
 
7
6
  import numpy as np
8
7
  from numpy.typing import NDArray
9
8
 
10
9
  _PKG_NAME: str = Path(__file__).parent.stem
11
10
 
12
- VERSION = "2024.739125.3"
11
+ VERSION = "2024.739127.1"
13
12
 
14
13
  __version__ = VERSION
15
14
 
@@ -25,21 +24,21 @@ if not DATA_DIR.is_dir():
25
24
  np.set_printoptions(precision=18)
26
25
 
27
26
 
28
- ArrayINT = NDArray[np.intp]
29
- ArrayFloat = NDArray[np.half | np.single | np.double]
27
+ type ArrayINT = NDArray[np.intp]
28
+ type ArrayFloat = NDArray[np.half | np.single | np.double]
30
29
 
31
30
 
32
- ArrayBoolean: TypeAlias = NDArray[np.bool_]
31
+ type ArrayBoolean = NDArray[np.bool_]
33
32
 
34
- ArrayDouble: TypeAlias = NDArray[np.double]
35
- ArrayBIGINT: TypeAlias = NDArray[np.int64]
33
+ type ArrayDouble = NDArray[np.double]
34
+ type ArrayBIGINT = NDArray[np.int64]
36
35
 
37
36
  DEFAULT_REC_RATE = 0.85
38
37
 
39
38
 
40
39
  @enum.unique
41
40
  class RECForm(enum.StrEnum):
42
- """Recapture rate - derivation methods."""
41
+ """For derivation of recapture rate from market shares."""
43
42
 
44
43
  INOUT = "inside-out"
45
44
  OUTIN = "outside-in"
@@ -49,7 +48,7 @@ class RECForm(enum.StrEnum):
49
48
  @enum.unique
50
49
  class UPPAggrSelector(enum.StrEnum):
51
50
  """
52
- Aggregator selection for GUPPI and diversion ratio
51
+ Aggregator for GUPPI and diversion ratio estimates.
53
52
 
54
53
  """
55
54
 
@@ -14,7 +14,7 @@ from importlib import resources
14
14
  from operator import itemgetter
15
15
  from pathlib import Path
16
16
  from types import MappingProxyType
17
- from typing import Any, NamedTuple, TypeAlias
17
+ from typing import Any, NamedTuple
18
18
 
19
19
  import msgpack # type: ignore
20
20
  import msgpack_numpy as m # type: ignore
@@ -95,7 +95,7 @@ class INVTableData(NamedTuple):
95
95
  data_array: ArrayBIGINT
96
96
 
97
97
 
98
- INVData: TypeAlias = Mapping[str, Mapping[str, Mapping[str, INVTableData]]]
98
+ type INVData = Mapping[str, Mapping[str, Mapping[str, INVTableData]]]
99
99
 
100
100
 
101
101
  def construct_data(
@@ -7,7 +7,7 @@ with a canvas on which to draw boundaries for Guidelines standards.
7
7
  from __future__ import annotations
8
8
 
9
9
  from dataclasses import dataclass
10
- from typing import Literal, TypeAlias
10
+ from typing import Literal
11
11
 
12
12
  import numpy as np
13
13
  from attrs import Attribute, field, frozen, validators
@@ -28,7 +28,7 @@ __version__ = VERSION
28
28
  mp.prec = 80
29
29
  mp.trap_complex = True
30
30
 
31
- HMGPubYear: TypeAlias = Literal[1992, 2004, 2010, 2023]
31
+ type HMGPubYear = Literal[1992, 2004, 2010, 2023]
32
32
 
33
33
 
34
34
  @dataclass(frozen=True)
@@ -48,10 +48,9 @@ with warnings.catch_warnings():
48
48
  mgn_kde = stats.gaussian_kde(mgn_data_obs, weights=mgn_data_wts, bw_method="silverman")
49
49
  mgn_kde.set_bandwidth(bw_method=mgn_kde.factor / 3.0)
50
50
 
51
- mgn_xvec = np.linspace(0, BIN_COUNT, 10**5) / BIN_COUNT
52
51
  mgn_ax.plot(
53
- mgn_xvec,
54
- mgn_kde(mgn_xvec),
52
+ (_xv := np.linspace(0, BIN_COUNT, 10**5) / BIN_COUNT),
53
+ mgn_kde(_xv),
55
54
  color="#004488",
56
55
  rasterized=True,
57
56
  label="Estimated Density",
@@ -34,7 +34,7 @@ from .data_generation_functions import (
34
34
  gen_share_data,
35
35
  parse_seed_seq_list,
36
36
  )
37
- from .upp_tests import SaveData, enf_cnts, save_data_to_hdf5
37
+ from .upp_tests import SaveData, compute_upp_test_counts, save_data_to_hdf5
38
38
 
39
39
  __version__ = VERSION
40
40
 
@@ -113,15 +113,13 @@ class MarketSample:
113
113
 
114
114
  enf_counts: UPPTestsCounts = field(default=None)
115
115
 
116
- def gen_market_sample(
116
+ def _gen_market_sample(
117
117
  self,
118
118
  /,
119
119
  *,
120
- sample_size: int = 10**6,
121
- seed_seq_list: Sequence[SeedSequence] | None = None,
122
- nthreads: int = 16,
123
- save_data_to_file: SaveData = False,
124
- saved_array_name_suffix: str = "",
120
+ sample_size: int,
121
+ seed_seq_list: Sequence[SeedSequence] | None,
122
+ nthreads: int,
125
123
  ) -> MarketDataSample:
126
124
  """
127
125
  Generate share, diversion ratio, price, and margin data for MarketSpec.
@@ -242,11 +240,11 @@ class MarketSample:
242
240
  self,
243
241
  /,
244
242
  *,
245
- sample_size: int,
246
- seed_seq_list: Sequence[SeedSequence],
247
- nthreads: int,
248
- save_data_to_file: SaveData,
249
- saved_array_name_suffix: str,
243
+ sample_size: int = 10**6,
244
+ seed_seq_list: Sequence[SeedSequence] | None = None,
245
+ nthreads: int = 16,
246
+ save_data_to_file: SaveData = False,
247
+ saved_array_name_suffix: str = "",
250
248
  ) -> None:
251
249
  """Populate :attr:`data` with generated data
252
250
 
@@ -258,7 +256,7 @@ class MarketSample:
258
256
 
259
257
  """
260
258
 
261
- self.data = self.gen_market_sample(
259
+ self.data = self._gen_market_sample(
262
260
  sample_size=sample_size, seed_seq_list=seed_seq_list, nthreads=nthreads
263
261
  )
264
262
 
@@ -275,7 +273,7 @@ class MarketSample:
275
273
  save_data_to_file=save_data_to_file,
276
274
  )
277
275
 
278
- def sim_enf_cnts(
276
+ def _sim_enf_cnts(
279
277
  self,
280
278
  _upp_test_parms: gbl.HMGThresholds,
281
279
  _sim_test_regime: UPPTestRegime,
@@ -322,7 +320,7 @@ class MarketSample:
322
320
 
323
321
  """
324
322
 
325
- _market_data_sample = self.gen_market_sample(
323
+ _market_data_sample = self._gen_market_sample(
326
324
  sample_size=sample_size, seed_seq_list=seed_seq_list, nthreads=nthreads
327
325
  )
328
326
 
@@ -339,7 +337,7 @@ class MarketSample:
339
337
  save_data_to_file=save_data_to_file,
340
338
  )
341
339
 
342
- _upp_test_arrays = enf_cnts(
340
+ _upp_test_arrays = compute_upp_test_counts(
343
341
  _market_data_sample, _upp_test_parms, _sim_test_regime
344
342
  )
345
343
 
@@ -351,7 +349,7 @@ class MarketSample:
351
349
 
352
350
  return _upp_test_arrays
353
351
 
354
- def sim_enf_cnts_ll(
352
+ def _sim_enf_cnts_ll(
355
353
  self,
356
354
  _enf_parm_vec: gbl.HMGThresholds,
357
355
  _sim_test_regime: UPPTestRegime,
@@ -435,7 +433,7 @@ class MarketSample:
435
433
  })
436
434
 
437
435
  _res_list = Parallel(n_jobs=_thread_count, prefer="threads")(
438
- delayed(self.sim_enf_cnts)(
436
+ delayed(self._sim_enf_cnts)(
439
437
  _enf_parm_vec,
440
438
  _sim_test_regime,
441
439
  **_sim_enf_cnts_kwargs,
@@ -474,7 +472,7 @@ class MarketSample:
474
472
  save_data_to_file: SaveData = False,
475
473
  saved_array_name_suffix: str = "",
476
474
  ) -> None:
477
- """Populate :attr:`enf_counts` etimated test counts.
475
+ """Populate :attr:`enf_counts` with estimated UPP test counts.
478
476
 
479
477
  Parameters
480
478
  ----------
@@ -510,7 +508,7 @@ class MarketSample:
510
508
  """
511
509
 
512
510
  if self.data is None:
513
- self.enf_counts = self.sim_enf_cnts_ll(
511
+ self.enf_counts = self._sim_enf_cnts_ll(
514
512
  _enf_parm_vec,
515
513
  _upp_test_regime,
516
514
  sample_size=sample_size,
@@ -520,7 +518,9 @@ class MarketSample:
520
518
  saved_array_name_suffix=saved_array_name_suffix,
521
519
  )
522
520
  else:
523
- self.enf_counts = enf_cnts(self.data, _enf_parm_vec, _upp_test_regime)
521
+ self.enf_counts = compute_upp_test_counts(
522
+ self.data, _enf_parm_vec, _upp_test_regime
523
+ )
524
524
  if save_data_to_file:
525
525
  save_data_to_hdf5(
526
526
  self.enf_counts,