4949 util ,
5050)
5151from ..retrieval .search import ContainerType
52+ from ..retrieval .series import SeriesValue
5253
5354__all__ = ("fetch_series" ,)
5455
55- from ..retrieval .series import SeriesValue
56-
5756
5857def fetch_series (
5958 * ,
@@ -113,6 +112,7 @@ def fetch_series(
113112
114113 return df
115114
115+
116116def _fetch_series (
117117 filter_ : Optional [_Filter ],
118118 attributes : _BaseAttributeFilter ,
@@ -125,69 +125,63 @@ def _fetch_series(
125125 tail_limit : Optional [int ],
126126 container_type : ContainerType ,
127127) -> tuple [dict [identifiers .RunAttributeDefinition , list [SeriesValue ]], dict [identifiers .SysId , str ]]:
128- sys_id_label_mapping : dict [identifiers .SysId , str ] = {}
129-
130- def go_fetch_sys_attrs () -> Generator [list [identifiers .SysId ], None , None ]:
131- for page in search .fetch_sys_id_labels (container_type )(
132- client = client ,
133- project_identifier = project_identifier ,
134- filter_ = filter_ ,
135- ):
136- sys_ids = []
137- for item in page .items :
138- sys_id_label_mapping [item .sys_id ] = item .label
139- sys_ids .append (item .sys_id )
140- yield sys_ids
141-
142- output = concurrency .generate_concurrently (
143- items = go_fetch_sys_attrs (),
128+ sys_id_label_mapping : dict [identifiers .SysId , str ] = {}
129+
130+ def go_fetch_sys_attrs () -> Generator [list [identifiers .SysId ], None , None ]:
131+ for page in search .fetch_sys_id_labels (container_type )(
132+ client = client ,
133+ project_identifier = project_identifier ,
134+ filter_ = filter_ ,
135+ ):
136+ sys_ids = []
137+ for item in page .items :
138+ sys_id_label_mapping [item .sys_id ] = item .label
139+ sys_ids .append (item .sys_id )
140+ yield sys_ids
141+
142+ output = concurrency .generate_concurrently (
143+ items = go_fetch_sys_attrs (),
144+ executor = executor ,
145+ downstream = lambda sys_ids : _components .fetch_attribute_definitions_split (
146+ client = client ,
147+ project_identifier = project_identifier ,
148+ attribute_filter = attributes ,
144149 executor = executor ,
145- downstream = lambda sys_ids : _components .fetch_attribute_definitions_split (
146- client = client ,
147- project_identifier = project_identifier ,
148- attribute_filter = attributes ,
149- executor = executor ,
150- fetch_attribute_definitions_executor = fetch_attribute_definitions_executor ,
151- sys_ids = sys_ids ,
152- downstream = lambda sys_ids_split , definitions_page : concurrency .generate_concurrently (
153- items = split .split_series_attributes (
154- items = (
155- identifiers .RunAttributeDefinition (
156- run_identifier = identifiers .RunIdentifier (project_identifier , sys_id ),
157- attribute_definition = definition ,
158- )
159- for sys_id in sys_ids_split
160- for definition in definitions_page .items
161- ),
150+ fetch_attribute_definitions_executor = fetch_attribute_definitions_executor ,
151+ sys_ids = sys_ids ,
152+ downstream = lambda sys_ids_split , definitions_page : concurrency .generate_concurrently (
153+ items = split .split_series_attributes (
154+ items = (
155+ identifiers .RunAttributeDefinition (
156+ run_identifier = identifiers .RunIdentifier (project_identifier , sys_id ),
157+ attribute_definition = definition ,
158+ )
159+ for sys_id in sys_ids_split
160+ for definition in definitions_page .items
162161 ),
163- executor = executor ,
164- downstream = lambda run_attribute_definitions_split : concurrency .generate_concurrently (
165- items = series .fetch_series_values (
166- client = client ,
167- run_attribute_definitions = run_attribute_definitions_split ,
168- include_inherited = lineage_to_the_root ,
169- container_type = container_type ,
170- step_range = step_range ,
171- tail_limit = tail_limit ,
172- ),
173- executor = executor ,
174- downstream = concurrency .return_value ,
162+ ),
163+ executor = executor ,
164+ downstream = lambda run_attribute_definitions_split : concurrency .return_value (
165+ series .fetch_series_values (
166+ client = client ,
167+ run_attribute_definitions = run_attribute_definitions_split ,
168+ include_inherited = lineage_to_the_root ,
169+ container_type = container_type ,
170+ step_range = step_range ,
171+ tail_limit = tail_limit ,
175172 ),
176173 ),
177174 ),
178- )
179- results : Generator [
180- util .Page [tuple [identifiers .RunAttributeDefinition , list [series .SeriesValue ]]], None , None
181- ] = concurrency .gather_results (output )
175+ ),
176+ )
182177
183- series_data : dict [identifiers .RunAttributeDefinition , list [series .SeriesValue ]] = {}
184- for result in results :
185- for run_attribute_definition , series_values in result .items :
186- series_data .setdefault (run_attribute_definition , []).extend (series_values )
178+ results : Generator [
179+ util .Page [tuple [identifiers .RunAttributeDefinition , list [series .SeriesValue ]]], None , None
180+ ] = concurrency .gather_results (output )
187181
188- return create_series_dataframe (
189- series_data ,
190- project_identifier ,
191- sys_id_label_mapping ,
192- index_column_name = "experiment" if container_type == ContainerType . EXPERIMENT else "run" ,
193- )
182+ series_data : dict [ identifiers . RunAttributeDefinition , list [ series . SeriesValue ]] = {}
183+ for result in results :
184+ for run_attribute_definition , series_values in result . items :
185+ series_data . setdefault ( run_attribute_definition , []). extend ( series_values )
186+
187+ return series_data , sys_id_label_mapping
0 commit comments