mergeron 2024.739097.4__py3-none-any.whl → 2024.739099.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.

@@ -15,12 +15,19 @@ from typing import Literal
15
15
  import numpy as np
16
16
  import re2 as re # type: ignore
17
17
  from jinja2 import Environment, FileSystemLoader, Template, select_autoescape
18
- from numpy.typing import NDArray
19
18
  from scipy.interpolate import interp1d # type: ignore
20
-
21
- from .. import _PKG_NAME, DATA_DIR, VERSION # noqa: TID252
19
+ from scipy.stats import beta, norm # type: ignore
20
+
21
+ from .. import ( # noqa: TID252
22
+ _PKG_NAME,
23
+ DATA_DIR,
24
+ TI,
25
+ VERSION,
26
+ ArrayBIGINT,
27
+ ArrayDouble,
28
+ ArrayINT,
29
+ )
22
30
  from ..core import ftc_merger_investigations_data as fid # noqa: TID252
23
- from ..core.proportions_tests import propn_ci # noqa: TID252
24
31
  from . import INVResolution
25
32
 
26
33
  __version__ = VERSION
@@ -293,7 +300,7 @@ def enf_stats_listing_by_group(
293
300
  _stats_group: StatsGrpSelector,
294
301
  _enf_spec: INVResolution,
295
302
  /,
296
- ) -> NDArray[np.int64]:
303
+ ) -> ArrayBIGINT:
297
304
  if _stats_group == StatsGrpSelector.HD:
298
305
  raise ValueError(
299
306
  f"Clearance/enforcement statistics, '{_stats_group}' not valied here."
@@ -328,7 +335,7 @@ def enf_cnts_listing_byfirmcount(
328
335
  _table_evid_cond: EVIDENConstants = EVIDENConstants.UR,
329
336
  _enf_spec: INVResolution = INVResolution.CLRN,
330
337
  /,
331
- ) -> NDArray[np.int64]:
338
+ ) -> ArrayBIGINT:
332
339
  if _data_period not in _data_array_dict:
333
340
  raise ValueError(
334
341
  f"Invalid value of data period, {f'"{_data_period}"'}."
@@ -364,7 +371,7 @@ def enf_cnts_listing_byhhianddelta(
364
371
  _table_evid_cond: EVIDENConstants = EVIDENConstants.UR,
365
372
  _enf_spec: INVResolution = INVResolution.CLRN,
366
373
  /,
367
- ) -> NDArray[np.int64]:
374
+ ) -> ArrayBIGINT:
368
375
  if _data_period not in _data_array_dict:
369
376
  raise ValueError(
370
377
  f"Invalid value of data period, {f'"{_data_period}"'}."
@@ -419,7 +426,7 @@ def table_no_lku(
419
426
  return _tno
420
427
 
421
428
 
422
- def enf_cnts_byfirmcount(_cnts_array: NDArray[np.int64], /) -> NDArray[np.int64]:
429
+ def enf_cnts_byfirmcount(_cnts_array: ArrayBIGINT, /) -> ArrayBIGINT:
423
430
  _ndim_in = 1
424
431
  return np.vstack([
425
432
  np.concatenate([
@@ -430,7 +437,7 @@ def enf_cnts_byfirmcount(_cnts_array: NDArray[np.int64], /) -> NDArray[np.int64]
430
437
  ])
431
438
 
432
439
 
433
- def enf_cnts_bydelta(_cnts_array: NDArray[np.int64], /) -> NDArray[np.int64]:
440
+ def enf_cnts_bydelta(_cnts_array: ArrayBIGINT, /) -> ArrayBIGINT:
434
441
  _ndim_in = 2
435
442
  return np.vstack([
436
443
  np.concatenate([
@@ -441,7 +448,7 @@ def enf_cnts_bydelta(_cnts_array: NDArray[np.int64], /) -> NDArray[np.int64]:
441
448
  ])
442
449
 
443
450
 
444
- def enf_cnts_byconczone(_cnts_array: NDArray[np.int64], /) -> NDArray[np.int64]:
451
+ def enf_cnts_byconczone(_cnts_array: ArrayBIGINT, /) -> ArrayBIGINT:
445
452
  # Prepare to tag clearance stats by presumption zone
446
453
  _hhi_zone_post_ranged = hhi_zone_post_ranger(_cnts_array[:, 0] / 1e4)
447
454
  _hhi_delta_ranged = hhi_delta_ranger(_cnts_array[:, 1] / 1e4)
@@ -513,7 +520,7 @@ def enf_cnts_byconczone(_cnts_array: NDArray[np.int64], /) -> NDArray[np.int64]:
513
520
 
514
521
 
515
522
  def enf_stats_table_onedim(
516
- _inparr: NDArray[np.float64 | np.int64],
523
+ _inparr: ArrayDouble | ArrayBIGINT | ArrayDouble | ArrayBIGINT,
517
524
  _totals_row: int | None = None,
518
525
  /,
519
526
  *,
@@ -568,7 +575,7 @@ def enf_stats_table_onedim(
568
575
 
569
576
 
570
577
  def enf_stats_table_byzone(
571
- _inparr: NDArray[np.float64 | np.int64],
578
+ _inparr: ArrayDouble | ArrayBIGINT | ArrayDouble | ArrayBIGINT,
572
579
  _totals_row: int | None = None,
573
580
  /,
574
581
  *,
@@ -650,8 +657,8 @@ def enf_stats_table_byzone(
650
657
 
651
658
 
652
659
  def _stats_formatted_row(
653
- _stats_row_cnt: NDArray[np.int64],
654
- _stats_row_tot: NDArray[np.int64],
660
+ _stats_row_cnt: ArrayBIGINT,
661
+ _stats_row_tot: ArrayBIGINT,
655
662
  _return_type_sel: StatsReturnSelector,
656
663
  /,
657
664
  ) -> list[list[str]]:
@@ -660,7 +667,7 @@ def _stats_formatted_row(
660
667
  match _return_type_sel:
661
668
  case StatsReturnSelector.RIN:
662
669
  _stats_row_ci = np.array([
663
- propn_ci(*g, method="Wilson")
670
+ _propn_ci(*g, method="Wilson")
664
671
  for g in zip(_stats_row_cnt[1:], _stats_row_tot[1:], strict=True)
665
672
  ])
666
673
  return [
@@ -715,6 +722,109 @@ def stats_print_rows(
715
722
  print()
716
723
 
717
724
 
725
+ def _propn_ci(
726
+ _npos: ArrayINT[TI] | int = 4,
727
+ _nobs: ArrayINT[TI] | int = 10,
728
+ /,
729
+ *,
730
+ alpha: float = 0.05,
731
+ method: Literal[
732
+ "Agresti-Coull", "Clopper-Pearson", "Exact", "Wilson", "Score"
733
+ ] = "Wilson",
734
+ ) -> tuple[
735
+ ArrayDouble | float, ArrayDouble | float, ArrayDouble | float, ArrayDouble | float
736
+ ]:
737
+ """Returns point estimates and confidence interval for a proportion
738
+
739
+ Methods "Clopper-Pearson" and "Exact" are synoymous [3]_. Similarly,
740
+ "Wilson" and "Score" are synonyms here.
741
+
742
+ Parameters
743
+ ----------
744
+ _npos
745
+ Number of positives
746
+
747
+ _nobs
748
+ Number of observed values
749
+
750
+ alpha
751
+ Significance level
752
+
753
+ method
754
+ Method to use for estimating confidence interval
755
+
756
+ Returns
757
+ -------
758
+ Raw and estimated proportions, and bounds of the confidence interval
759
+
760
+
761
+ References
762
+ ----------
763
+
764
+ .. [3] Alan Agresti & Brent A. Coull (1998) Approximate is Better
765
+ than “Exact” for Interval Estimation of Binomial Proportions,
766
+ The American Statistician, 52:2, 119-126,
767
+ https://doi.org/10.1080/00031305.1998.10480550
768
+
769
+ """
770
+
771
+ for _f in _npos, _nobs:
772
+ if not isinstance(_f, int | np.integer):
773
+ raise ValueError(
774
+ f"Count, {_f!r} must have type that is a subtype of np.integer."
775
+ )
776
+
777
+ if not _nobs:
778
+ return (np.nan, np.nan, np.nan, np.nan)
779
+
780
+ _raw_phat: ArrayDouble | float = _npos / _nobs
781
+ _est_phat: ArrayDouble | float
782
+ _est_ci_l: ArrayDouble | float
783
+ _est_ci_u: ArrayDouble | float
784
+
785
+ match method:
786
+ case "Clopper-Pearson" | "Exact":
787
+ _est_ci_l, _est_ci_u = (
788
+ beta.ppf(*_f)
789
+ for _f in (
790
+ (alpha / 2, _npos, _nobs - _npos + 1),
791
+ (1 - alpha / 2, _npos + 1, _nobs - _npos),
792
+ )
793
+ )
794
+ _est_phat = 1 / 2 * (_est_ci_l + _est_ci_u)
795
+
796
+ case "Agresti-Coull":
797
+ _zsc = norm.ppf(1 - alpha / 2)
798
+ _zscsq = _zsc * _zsc
799
+ _adjmt = 4 if alpha == 0.05 else _zscsq
800
+ _est_phat = (_npos + _adjmt / 2) / (_nobs + _adjmt)
801
+ _est_ci_l, _est_ci_u = (
802
+ _est_phat + _g
803
+ for _g in [
804
+ _f * _zsc * np.sqrt(_est_phat * (1 - _est_phat) / (_nobs + _adjmt))
805
+ for _f in (-1, 1)
806
+ ]
807
+ )
808
+
809
+ case "Wilson" | "Score":
810
+ _zsc = norm.ppf(1 - alpha / 2)
811
+ _zscsq = _zsc * _zsc
812
+ _est_phat = (_npos + _zscsq / 2) / (_nobs + _zscsq)
813
+ _est_ci_l, _est_ci_u = (
814
+ _est_phat
815
+ + _f
816
+ * _zsc
817
+ * np.sqrt(_nobs * _raw_phat * (1 - _raw_phat) + _zscsq / 4)
818
+ / (_nobs + _zscsq)
819
+ for _f in (-1, 1)
820
+ )
821
+
822
+ case _:
823
+ raise ValueError(f"Method, {f'"{method}"'} not yet implemented.")
824
+
825
+ return _raw_phat, _est_phat, _est_ci_l, _est_ci_u
826
+
827
+
718
828
  def render_table_pdf(
719
829
  _table_dottex_pathlist: Sequence[str], _table_coll_path: str, /
720
830
  ) -> None:
mergeron/gen/upp_tests.py CHANGED
@@ -13,9 +13,19 @@ import numpy as np
13
13
  import tables as ptb # type: ignore
14
14
  from joblib import Parallel, cpu_count, delayed # type: ignore
15
15
  from numpy.random import SeedSequence
16
- from numpy.typing import NDArray
17
16
 
18
- from .. import VERSION, RECConstants, UPPAggrSelector # noqa: TID252
17
+ from .. import ( # noqa: TID252
18
+ TF,
19
+ TI,
20
+ VERSION,
21
+ ArrayBIGINT,
22
+ ArrayBoolean,
23
+ ArrayDouble,
24
+ ArrayFloat,
25
+ ArrayINT,
26
+ RECConstants,
27
+ UPPAggrSelector,
28
+ )
19
29
  from ..core import guidelines_boundaries as gbl # noqa: TID252
20
30
  from . import (
21
31
  EMPTY_ARRAY_DEFAULT,
@@ -496,7 +506,11 @@ def save_data_to_hdf5(
496
506
 
497
507
 
498
508
  def save_array_to_hdf5(
499
- _array_obj: NDArray[np.float64 | np.int64 | np.bool_],
509
+ _array_obj: ArrayFloat[TF]
510
+ | ArrayINT[TI]
511
+ | ArrayDouble
512
+ | ArrayBIGINT
513
+ | ArrayBoolean,
500
514
  _array_name: str,
501
515
  _h5_group: ptb.Group,
502
516
  _h5_file: ptb.File,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mergeron
3
- Version: 2024.739097.4
3
+ Version: 2024.739099.1
4
4
  Summary: Merger Policy Analysis using Python
5
5
  License: MIT
6
6
  Keywords: merger policy analysis,merger guidelines,merger screening,policy presumptions,concentration standards,upward pricing pressure,GUPPI
@@ -83,29 +83,6 @@ Documentation for this package is in the form of the API Reference. Documentatio
83
83
 
84
84
  help(market_sample.MarketSample)
85
85
 
86
- "Extras" Subpackage
87
- ---------------------
88
-
89
- The "Extras" sub-package includes a small number of modules potentially useful to users, but which do not implement the principal functions of the package, and are hence considered "extras" or "external" modules. One of these modules is, in fact, repackaged here although published independently.
90
-
91
- On of the external modules provides methods for estimating confidence intervals for proportions and for contrasts (differences) in proportions. This module improve is coded for conformance to the literature and to results from the corresponding modules in :code:`R`. Although written from scratch, the APIs implemented in the module included here are designed for consistency with the APIs in, :code:`statsmodels.stats.proportion` from the package, :code:`statsmodels` (https://pypi.org/project/statsmodels/). To access these directly:
92
-
93
- .. code-block:: python
94
-
95
- import mergeron.ext.proportions_tests as prci
96
-
97
- Module :code:`mergeron.ext.xlsxw_helper` is useful for writing highly formatted output to spreadsheets with xlsx format. The class, :code:`mergeron.ext.xlsxw_helper.CFmt` and function, :code:`mergeron.ext.xlsxw_helper.array_to_sheet` are of particular interest, and can be accessed as :code:`xlh.CFmt` and :code:`xlh.array_to_sheet` with the following import:
98
-
99
- .. code-block:: python
100
-
101
- import mergeron.ext.xlsxw_helper as xlsxw_helper
102
-
103
- A recent version of Paul Tol's python module, :code:`tol_colors.py`, which provides high-contrast color schemes for making displays with improved visibility for individuals with color-blindness, is redistributed within this package. Other than re-formatting and type annotation, the :code:`mergeron.ext.tol_colors` module is re-distributed as downloaded from, https://personal.sron.nl/~pault/data/tol_colors.py. The :code:`tol_colors.py` module is distributed under the Standard 3-clause BSD license. To access the :code:`mergeron.ext.tol_colors` module directly:
104
-
105
- .. code-block:: python
106
-
107
- import mergeron.ext.tol_colors as ptc
108
-
109
86
  .. image:: https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json
110
87
  :alt: Poetry
111
88
  :target: https://python-poetry.org/
@@ -1,12 +1,12 @@
1
1
  mergeron/License.txt,sha256=7iX-y0EyjkbVJKJLS4ZKzuuE1wd0lryfsD_IytLG8lQ,1246
2
- mergeron/__init__.py,sha256=p_4HhYPKBwm93IWuOVlQ_eINlxG6ozyvujs8iaDEYFM,1180
2
+ mergeron/__init__.py,sha256=u08ycqko_RgETIhaYivtm7Tglj2dZFk83KUJIbPRuL4,1541
3
3
  mergeron/core/__init__.py,sha256=KtjBlZOl7jwBCAUhrTJB9PdrN39YLYytNiSUSM_gRmA,62
4
- mergeron/core/damodaran_margin_data.py,sha256=PRbdNHqDRN4tG3MI9ZTsilx8SkJ5mZYQc7SgRxcT3YI,8606
5
- mergeron/core/ftc_merger_investigations_data.py,sha256=Akwc0spRhydXd17j2t37V6EijlJMBk54pcYCNDaykns,28205
6
- mergeron/core/guidelines_boundaries.py,sha256=__OHme8aGtwOgRXKp56WdX7k4vssAVQ8Ub54XwpS7mg,15621
7
- mergeron/core/guidelines_boundary_functions.py,sha256=l5fNs65ciEVH-K-QfR8clsfY89xqdf79UIyyZWlSGxU,29718
8
- mergeron/core/guidelines_boundary_functions_extra.py,sha256=LHeYOHAkhVuwmzOFzP1KqyXNE58BIWqW4pzRkceJx_Q,11316
9
- mergeron/core/pseudorandom_numbers.py,sha256=k3sDs_NJ2jXlkIWKQ6iiTB5n_QS0RoJ-sqzvFYkC7pY,9277
4
+ mergeron/core/damodaran_margin_data.py,sha256=rMrgN1Qtw572a0ftY97OOj4otq8ldlLrcOi-bcE-org,8554
5
+ mergeron/core/ftc_merger_investigations_data.py,sha256=oL_4yrNPpjuNIluBsDc51lYd2Z4NBBrd7-sHKd3FCbg,28129
6
+ mergeron/core/guidelines_boundaries.py,sha256=Lv-7EE7b2SiudpRjW3gFY1uHu-K0UdesewwiqaqjcOw,15585
7
+ mergeron/core/guidelines_boundary_functions.py,sha256=HbuVOpQWlbIhvlWYvL2PXovase5az8DFU82woVl1VLo,29685
8
+ mergeron/core/guidelines_boundary_functions_extra.py,sha256=t84dMsaMKnYUNuvvGrMCP6vI8MDn88PJOgGZlNe1Zts,11280
9
+ mergeron/core/pseudorandom_numbers.py,sha256=cJEWDTfy9CUTzR_di6Fm1Vl1Le6xWoU8wFHbYVMEuLI,9225
10
10
  mergeron/data/__init__.py,sha256=KtjBlZOl7jwBCAUhrTJB9PdrN39YLYytNiSUSM_gRmA,62
11
11
  mergeron/data/damodaran_margin_data.xls,sha256=Qggl1p5nkOMJI8YUXhkwXQRz-OhRSqBTzz57N0JQyYA,79360
12
12
  mergeron/data/damodaran_margin_data_dict.msgpack,sha256=sr6s4L69kposEpzGI7jpPb4ULz0UpY-bEYfeNi6UlRA,57621
@@ -20,17 +20,13 @@ mergeron/data/jinja2_LaTeX_templates/mergeron_table_collection_template.tex.jinj
20
20
  mergeron/data/jinja2_LaTeX_templates/setup_tikz_tables.tex,sha256=1hw3RINDtBrh9ZEToMIiNFIu9rozcPwRly69-5O_0UQ,3207
21
21
  mergeron/demo/__init__.py,sha256=KtjBlZOl7jwBCAUhrTJB9PdrN39YLYytNiSUSM_gRmA,62
22
22
  mergeron/demo/visualize_empirical_margin_distribution.py,sha256=v1xFJumBX2Ooye82kSSgly-_GpFVkYSDqBwM__rcmZY,2363
23
- mergeron/ext/__init__.py,sha256=KtjBlZOl7jwBCAUhrTJB9PdrN39YLYytNiSUSM_gRmA,62
24
- mergeron/ext/proportions_tests.py,sha256=akq0Xhdgtst4RAT42_E5cBD_kATq_V4bQeBznmzRSLg,15267
25
- mergeron/ext/tol_colors.py,sha256=QBw8s-ZGpUpIIYOplHbLFZSXVoa6eDDJDtzSScP954E,22303
26
- mergeron/ext/xlsxw_helper.py,sha256=GqetJK5tLfg8JmXKrWIOHaCDHt_mspcopiAK3xxtqhM,18018
27
- mergeron/gen/__init__.py,sha256=Ky1p93L-epw42g8HDIcfiENGT1iiXdolnsv12ZUWGM4,17169
28
- mergeron/gen/_data_generation_functions.py,sha256=boNQkDtarx_BqYHWjlsIXSQHqOBvgBcI_R53UfT66qg,27763
29
- mergeron/gen/data_generation.py,sha256=n_rdi6Zk5-2Q0K_xXdWI14sj9XZyrF57hnyqvBf5v6Y,8531
30
- mergeron/gen/enforcement_stats.py,sha256=Hr-w3LZ9SJD4A1RZS1KMhXwuKyGzPC7eeNQullWZRNU,24410
23
+ mergeron/gen/__init__.py,sha256=Tm_eDiZkOwoOrfKyRu_3jkmNpFqyBMxfMY-Lu9BYAnc,17050
24
+ mergeron/gen/_data_generation_functions.py,sha256=I4J8cDTMR27683Kr18ST1nzdA8kCZVKz7cyk8y3rfMo,27582
25
+ mergeron/gen/data_generation.py,sha256=dj9otFi1OE3Eo7f32BD0ZXm9Xvlg0fCp4DDQ_XhDN_w,8479
26
+ mergeron/gen/enforcement_stats.py,sha256=6IekvV8qvGFid6xbvqOazKYytMZQEwLyApt5TzTFPWU,27421
31
27
  mergeron/gen/market_sample.py,sha256=HkzRFTKBXYIs2HbAyVDUiUHo9nCtAciSn5sohR-34cM,4282
32
- mergeron/gen/upp_tests.py,sha256=N-spIAYKPGJngtlckSjhQGcFBZv_sVZDvCHYzy0TxSc,17132
28
+ mergeron/gen/upp_tests.py,sha256=xYhzWBgJJxYtz6VlGrrtx_cwwSZD3FdTDLD5zB1RDng,17261
33
29
  mergeron/py.typed,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
34
- mergeron-2024.739097.4.dist-info/METADATA,sha256=GMyImdNjjsqCS54AHzAvUzVBozx2HhGUyqoIZ2MVZkY,12948
35
- mergeron-2024.739097.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
36
- mergeron-2024.739097.4.dist-info/RECORD,,
30
+ mergeron-2024.739099.1.dist-info/METADATA,sha256=9AN4mWKYnvtQInNpO-ytzRthOUI3nB63FcnVVBNjD_s,10922
31
+ mergeron-2024.739099.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ mergeron-2024.739099.1.dist-info/RECORD,,
mergeron/ext/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- from .. import VERSION # noqa: TID252
2
-
3
- __version__ = VERSION