rapidata 2.9.0__py3-none-any.whl → 2.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 rapidata might be problematic. Click here for more details.

@@ -8,30 +8,40 @@ class RapidataResults(dict):
8
8
  A specialized dictionary class for handling Rapidata API results.
9
9
  Extends the built-in dict class with specialized methods.
10
10
  """
11
- def to_pandas(self) -> pd.DataFrame:
11
+ def to_pandas(self, split_detailed: bool = False) -> pd.DataFrame:
12
12
  """
13
+ This method is currently under development.
14
+
13
15
  Converts the results to a pandas DataFrame.
14
16
 
15
- For Compare results, creates standardized A/B columns for metrics like:
16
- - aggregatedResults
17
- - aggregatedResultsRatios
18
- - summedUserScores
19
- - summedUserScoresRatios
20
-
17
+ For Compare results, creates standardized A/B columns for metrics.
21
18
  For regular results, flattens nested dictionaries into columns with underscore-separated names.
22
19
 
20
+ Args:
21
+ split_detailed: If True, splits each datapoint by its detailed results,
22
+ creating a row for each response with global metrics copied.
23
+
23
24
  Returns:
24
25
  pd.DataFrame: A DataFrame containing the processed results
26
+
27
+ Raises:
28
+ ValueError: If split_detailed is True but no detailed results are found
25
29
  """
26
30
  if "results" not in self or not self["results"]:
27
31
  return pd.DataFrame()
28
32
 
33
+ if self["info"].get("orderType") is None:
34
+ print("Warning: Results are old and Order type is not specified. Dataframe might be wrong.")
35
+
36
+ # Check for detailed results if split_detailed is True
37
+ if split_detailed:
38
+ if not self._has_detailed_results():
39
+ raise ValueError("No detailed results found in the data")
40
+ return self._to_pandas_with_detailed_results()
41
+
29
42
  if self["info"].get("orderType") == "Compare":
30
43
  return self._compare_to_pandas()
31
44
 
32
- if self["info"].get("orderType") is None:
33
- print("Warning: Results are old and Order type is not specified. Dataframe might be wrong.")
34
-
35
45
  # Get the structure from first item
36
46
  first_item = self["results"][0]
37
47
  columns = []
@@ -51,6 +61,68 @@ class RapidataResults(dict):
51
61
 
52
62
  return pd.DataFrame(data, columns=Index(columns))
53
63
 
64
+ def _has_detailed_results(self) -> bool:
65
+ """
66
+ Checks if the results contain detailed results.
67
+
68
+ Returns:
69
+ bool: True if detailed results exist, False otherwise
70
+ """
71
+ if not self.get("results"):
72
+ return False
73
+
74
+ first_result = self["results"][0]
75
+ return "detailedResults" in first_result and isinstance(first_result["detailedResults"], list)
76
+
77
+ def _to_pandas_with_detailed_results(self) -> pd.DataFrame:
78
+ """
79
+ Converts results to a pandas DataFrame with detailed results split into separate rows.
80
+
81
+ Returns:
82
+ pd.DataFrame: A DataFrame with one row per detailed result
83
+ """
84
+ rows = []
85
+
86
+ for result in self["results"]:
87
+ # Get all non-detailed results fields
88
+ base_data = {k: v for k, v in result.items() if k != "detailedResults"}
89
+
90
+ # Process each detailed result
91
+ for detailed_result in result["detailedResults"]:
92
+ row = base_data.copy() # Copy base data for each detailed result
93
+
94
+ # Add flattened detailed result data
95
+ flattened = self._flatten_dict(detailed_result)
96
+ for key, value in flattened.items():
97
+ row[key] = value
98
+
99
+ rows.append(row)
100
+
101
+ return pd.DataFrame(rows)
102
+
103
+ def _flatten_dict(self, d: dict[str, Any], parent_key: str = '') -> dict[str, Any]:
104
+ """
105
+ Flattens a nested dictionary into a single-level dictionary with underscore-separated keys.
106
+
107
+ Args:
108
+ d: The dictionary to flatten
109
+ parent_key: The parent key for nested dictionaries
110
+
111
+ Returns:
112
+ dict: A flattened dictionary
113
+ """
114
+ items: list[tuple[str, Any]] = []
115
+
116
+ for key, value in d.items():
117
+ new_key = f"{parent_key}_{key}" if parent_key else key
118
+
119
+ if isinstance(value, dict):
120
+ items.extend(self._flatten_dict(value, new_key).items())
121
+ else:
122
+ items.append((new_key, value))
123
+
124
+ return dict(items)
125
+
54
126
  def _build_column_structure(
55
127
  self,
56
128
  d: dict[str, Any],
@@ -97,7 +169,7 @@ class RapidataResults(dict):
97
169
  d = d.get(key, {})
98
170
  return d.get(path[-1])
99
171
 
100
- def _compare_to_pandas(self):
172
+ def _compare_to_pandas(self) -> pd.DataFrame:
101
173
  """
102
174
  Converts Compare results to a pandas DataFrame dynamically.
103
175
  """
@@ -132,7 +204,7 @@ class RapidataResults(dict):
132
204
 
133
205
  return pd.DataFrame(rows)
134
206
 
135
- def to_json(self, path: str="./results.json"):
207
+ def to_json(self, path: str="./results.json") -> None:
136
208
  """
137
209
  Saves the results to a JSON file.
138
210
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: rapidata
3
- Version: 2.9.0
3
+ Version: 2.10.0
4
4
  Summary: Rapidata package containing the Rapidata Python Client to interact with the Rapidata Web API in an easy way.
5
5
  License: Apache-2.0
6
6
  Author: Rapidata AG
@@ -399,7 +399,7 @@ rapidata/rapidata_client/order/_rapidata_dataset.py,sha256=ipSLGEQm6Z5Gj0Z13SmE5
399
399
  rapidata/rapidata_client/order/_rapidata_order_builder.py,sha256=N6mqmgneJSsb_no_Ps9BG3EhDekLgKxFYpjDCN-VVeg,13095
400
400
  rapidata/rapidata_client/order/rapidata_order.py,sha256=XI9xeEtqZIwdAXLe9Pn4RO8iPNSoBToQ2WD62TRWzTE,9115
401
401
  rapidata/rapidata_client/order/rapidata_order_manager.py,sha256=4wW5xtmEtdewFGGwMWSMbdLZpHvygtLCfYNv4lcHGg8,27271
402
- rapidata/rapidata_client/order/rapidata_results.py,sha256=tCQgfv70FHJBcVsgAjqkYZB8ZvqrPGD_hlOmzArlLHg,5037
402
+ rapidata/rapidata_client/order/rapidata_results.py,sha256=_Upy8IDEzkMJJ7QXz-MnZ3ONkhZd2uZ6KPW0SyJ7s40,7866
403
403
  rapidata/rapidata_client/rapidata_client.py,sha256=A9mnSX6wzVF9TxS1YH87hTi4jCn75dIuP3KZj5Y_vFg,1957
404
404
  rapidata/rapidata_client/referee/__init__.py,sha256=q0Hv9nmfEpyChejtyMLT8hWKL0vTTf_UgUXPYNJ-H6M,153
405
405
  rapidata/rapidata_client/referee/_base_referee.py,sha256=MdFOhdxt3sRnWXLDKLJZKFdVpjBGn9jypPnWWQ6msQA,496
@@ -447,7 +447,7 @@ rapidata/service/credential_manager.py,sha256=Of0BQs_V1T7rkrWX9groLX790nOknaARwn
447
447
  rapidata/service/local_file_service.py,sha256=pgorvlWcx52Uh3cEG6VrdMK_t__7dacQ_5AnfY14BW8,877
448
448
  rapidata/service/openapi_service.py,sha256=Z4NrAuilLlIWBdGOv6otz36tHS_vvU36w5jmvOUTmqo,3198
449
449
  rapidata/service/token_manager.py,sha256=JZ5YbR5Di8dO3H4kK11d0kzWlrXxjgCmeNkHA4AapCM,6425
450
- rapidata-2.9.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
451
- rapidata-2.9.0.dist-info/METADATA,sha256=7GbcyE9ZroILh90eiE2K7HuX_33Xoon2mZP8pRTjL_E,1146
452
- rapidata-2.9.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
453
- rapidata-2.9.0.dist-info/RECORD,,
450
+ rapidata-2.10.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
451
+ rapidata-2.10.0.dist-info/METADATA,sha256=Dtdyhe-hoUqSfuARXuuqg2ilt1NVgCxB9X1wo1r_DFA,1147
452
+ rapidata-2.10.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
453
+ rapidata-2.10.0.dist-info/RECORD,,