Skip to content

Commit 8e3cdcd

Browse files
committed
Merge remote-tracking branch 'origin/master'
# Conflicts: # hypex/comparators/__init__.py
2 parents e41e0f0 + de67e79 commit 8e3cdcd

File tree

25 files changed

+281
-327
lines changed

25 files changed

+281
-327
lines changed

examples/experiments/performance_test/performance_test.py

Lines changed: 155 additions & 157 deletions
Large diffs are not rendered by default.

hypex/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.1"
1+
__version__ = "1.0.2"

hypex/analyzers/ab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def execute(self, data: ExperimentData) -> ExperimentData:
117117
for i in range(0, len(analysis_ids), len(analysis_ids) // num_groups):
118118
value = t_data.iloc[i : i + len(analysis_ids) // num_groups][f]
119119
multitest_pvalues = self._add_pvalues(multitest_pvalues, value, f)
120-
analysis_data[f"{c} {f} {groups[i//num_groups + 1][0]}"] = (
120+
analysis_data[f"{c} {f} {groups[i // num_groups + 1][0]}"] = (
121121
value.mean()
122122
)
123123
if c not in ["UTest", "TTest"]:
@@ -126,7 +126,7 @@ def execute(self, data: ExperimentData) -> ExperimentData:
126126
for idx, value in zip(indexes, values):
127127
name = idx.split(ID_SPLIT_SYMBOL)[-1]
128128
analysis_data[
129-
f"{c} {name[name.find(NAME_BORDER_SYMBOL) + 1: name.rfind(NAME_BORDER_SYMBOL)]}"
129+
f"{c} {name[name.find(NAME_BORDER_SYMBOL) + 1 : name.rfind(NAME_BORDER_SYMBOL)]}"
130130
] = value[0]
131131

132132
analysis_dataset = Dataset.from_dict(

hypex/comparators/abstract.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,20 @@ def _extract_dataset(
134134
return result
135135
return Dataset.from_dict(compare_result, roles, BackendsEnum.pandas)
136136

137-
# TODO выделить в отдельную функцию с кваргами (нужно для альфы)
138-
139137
@staticmethod
140138
def _grouping_data_split(
141139
grouping_data: dict[str, Dataset],
142140
compare_by: Literal["groups", "columns", "columns_in_groups", "cross"],
143141
target_fields: list[str],
144142
baseline_field: str | None = None,
145143
) -> GroupingDataType:
146-
if isinstance(grouping_data, dict):
147-
compared_data = [(name, data) for name, data in grouping_data.items()]
148-
baseline_data = [compared_data.pop(0)]
149-
else:
144+
if not isinstance(grouping_data, dict):
150145
raise TypeError(
151146
f"Grouping data must be dict of strings and datasets, but got {type(grouping_data)}"
152147
)
153148

149+
compared_data = list(grouping_data.items())
150+
baseline_data = [compared_data.pop(0)]
154151
baseline_data = [
155152
(
156153
bucket[0],
@@ -166,7 +163,7 @@ def _grouping_data_split(
166163

167164
@staticmethod
168165
def _split_ds_into_columns(
169-
data: list[tuple[str, Dataset]]
166+
data: list[tuple[str, Dataset]],
170167
) -> list[tuple[str, Dataset]]:
171168
result = [
172169
(bucket[0], bucket[1][column])
@@ -354,7 +351,6 @@ def calc(
354351
) = None,
355352
**kwargs,
356353
) -> dict:
357-
358354
if compare_by is None and target_fields_data is None:
359355
raise ValueError(
360356
"You should pass either compare_by or target_fields argument."
@@ -390,9 +386,7 @@ def execute(self, data: ExperimentData) -> ExperimentData:
390386
)
391387

392388
if len(target_fields_data.columns) == 0:
393-
if (
394-
data.ds.tmp_roles
395-
): # if the column is not suitable for the test, then the target will be empty, but if there is a role tempo, then this is normal behavior
389+
if data.ds.tmp_roles: # if the column is not suitable for the test, then the target will be empty, but if there is a role tempo, then this is normal behavior
396390
return data
397391
else:
398392
raise NoColumnsError(TargetRole().role_name)

hypex/comparators/comparators.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ def _inner_function(
8181

8282

8383
class PSI(Comparator):
84-
8584
@classmethod
8685
def _inner_function(
8786
cls, data: Dataset, test_data: Dataset | None = None, **kwargs

hypex/comparators/distances.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
class MahalanobisDistance(Calculator):
21-
2221
def __init__(
2322
self,
2423
grouping_role: ABCRole | None = None,
@@ -107,7 +106,6 @@ def calc(
107106
grouping_data, target_fields=target_fields, old_data=data, **kwargs
108107
)
109108

110-
# TODO выделить в отдельную функцию с кваргами (нужно для альфы)
111109
def execute(self, data: ExperimentData) -> ExperimentData:
112110
group_field, target_fields = self._get_fields(data=data)
113111
self.key = str(

hypex/comparators/hypothesis_testing.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def _inner_function(
2626

2727

2828
class KSTest(StatHypothesisTesting):
29-
3029
@property
3130
def search_types(self) -> list[type] | None:
3231
return NUMBER_TYPES_LIST
@@ -41,7 +40,6 @@ def _inner_function(
4140

4241

4342
class UTest(StatHypothesisTesting):
44-
4543
@property
4644
def search_types(self) -> list[type] | None:
4745
return NUMBER_TYPES_LIST
@@ -56,7 +54,6 @@ def _inner_function(
5654

5755

5856
class Chi2Test(StatHypothesisTesting):
59-
6057
@property
6158
def search_types(self) -> list[type] | None:
6259
return [str]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .comparators import Comparator
1212

1313

14-
class TestPower(Comparator, ABC):
14+
class PowerTesting(Comparator, ABC):
1515
def __init__(
1616
self,
1717
grouping_role: ABCRole | None = None,
@@ -45,7 +45,7 @@ def execute(self, data: ExperimentData) -> ExperimentData:
4545
return super().execute(data)
4646

4747

48-
class MDEBySize(TestPower):
48+
class MDEBySize(PowerTesting):
4949
def _set_value(
5050
self, data: ExperimentData, value: Dataset | None = None, key: Any = None
5151
) -> ExperimentData:

hypex/dataset/dataset.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040

4141

4242
class Dataset(DatasetBase):
43-
4443
class Locker:
45-
4644
def __init__(self, backend, roles):
4745
self.backend = backend
4846
self.roles = roles
@@ -348,7 +346,6 @@ def _check_other_dataset(self, other):
348346
def astype(
349347
self, dtype: dict[str, type], errors: Literal["raise", "ignore"] = "raise"
350348
) -> Dataset:
351-
352349
for col, _ in dtype.items():
353350
if (errors == "raise") and (col not in self.columns):
354351
raise KeyError(f"Column '{col}' does not exist in the Dataset.")
@@ -734,7 +731,6 @@ def replace(
734731

735732

736733
class ExperimentData:
737-
738734
def __init__(self, data: Dataset):
739735
self._data = data
740736
self.additional_fields = Dataset.create_empty(index=data.index)
@@ -820,7 +816,6 @@ def get_ids(
820816
searched_space: ExperimentDataEnum | Iterable[ExperimentDataEnum] | None = None,
821817
key: str | None = None,
822818
) -> dict[str, dict[str, list[str]]]:
823-
824819
def check_id(id_: str, class_: str) -> bool:
825820
result = id_[: id_.find(ID_SPLIT_SYMBOL)] == class_
826821

@@ -933,7 +928,6 @@ def field_data_search(
933928

934929

935930
class DatasetAdapter(Adapter):
936-
937931
@staticmethod
938932
def to_dataset(
939933
data: dict | Dataset | pd.DataFrame | list | str | int | float | bool,

hypex/dataset/roles.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212

1313
class ABCRole(ABC):
14-
1514
_role_name: RoleNameType = "Abstract"
1615

1716
def __init__(self, data_type: DefaultRoleTypes | None = None):
@@ -26,54 +25,46 @@ def __repr__(self) -> str:
2625

2726

2827
class InfoRole(ABCRole):
29-
3028
_role_name: RoleNameType = "Info"
3129

3230

3331
class StratificationRole(ABCRole):
34-
3532
_role_name: RoleNameType = "Stratification"
3633

3734
def __init__(self, data_type: CategoricalTypes | None = None):
3835
super().__init__(data_type)
3936

4037

4138
class GroupingRole(ABCRole):
42-
4339
_role_name: RoleNameType = "Grouping"
4440

4541
def __init__(self, data_type: CategoricalTypes | None = None):
4642
super().__init__(data_type)
4743

4844

4945
class TreatmentRole(ABCRole):
50-
5146
_role_name: RoleNameType = "Treatment"
5247

5348

5449
class TargetRole(ABCRole):
55-
5650
_role_name: RoleNameType = "Target"
5751

5852
def __init__(self, data_type: TargetRoleTypes | None = None):
5953
super().__init__(data_type)
6054

6155

6256
class FeatureRole(ABCRole):
63-
6457
_role_name: RoleNameType = "Feature"
6558

6659

6760
class PreTargetRole(ABCRole):
68-
6961
_role_name: RoleNameType = "PreTarget"
7062

7163
def __init__(self, data_type: TargetRoleTypes | None = None):
7264
super().__init__(data_type)
7365

7466

7567
class StatisticRole(ABCRole):
76-
7768
_role_name: RoleNameType = "Statistic"
7869

7970

@@ -95,58 +86,47 @@ class TempRole(ABCRole):
9586

9687

9788
class TempTreatmentRole(TempRole, TreatmentRole):
98-
9989
_role_name: RoleNameType = "TempTreatment"
10090

10191

10292
class TempTargetRole(TempRole, TargetRole):
103-
10493
_role_name: RoleNameType = "TempTarget"
10594

10695

10796
class TempGroupingRole(TempRole, GroupingRole):
108-
10997
_role_name: RoleNameType = "TempGrouping"
11098

11199

112100
class DefaultRole(ABCRole):
113-
114101
_role_name: RoleNameType = "Default"
115102

116103

117104
class ReportRole(ABCRole):
118-
119105
_role_name: RoleNameType = "Report"
120106

121107

122108
# ___________________________________________________________________________________________
123109
class AdditionalRole(ABCRole):
124-
125110
_role_name: RoleNameType = "Additional"
126111

127112

128113
class AdditionalTreatmentRole(AdditionalRole):
129-
130114
_role_name: RoleNameType = "AdditionalTreatment"
131115

132116

133117
class AdditionalGroupingRole(AdditionalRole):
134-
135118
_role_name: RoleNameType = "AdditionalGrouping"
136119

137120

138121
class AdditionalTargetRole(AdditionalRole):
139-
140122
_role_name: RoleNameType = "AdditionalTarget"
141123

142124

143125
class AdditionalPreTargetRole(AdditionalRole):
144-
145126
_role_name: RoleNameType = "AdditionalPreTarget"
146127

147128

148129
class AdditionalMatchingRole(AdditionalRole):
149-
150130
_role_name: RoleNameType = "AdditionalMatching"
151131

152132

0 commit comments

Comments
 (0)