MCPcopy Create free account
hub / github.com/alibaba/GraphScope / normalize_parameter_edges

Function normalize_parameter_edges

python/graphscope/framework/graph_utils.py:343–405  ·  view source on GitHub ↗

Normalize parameters user passed in. Since parameters are very flexible, we need to be careful about it. Args: edges (Union[ Mapping[str, Union[Sequence, LoaderVariants, Mapping]], Tuple, LoaderVariants ]): Edges definition. id_type (str): Type of vertex original

(
    edges: Union[
        Mapping[str, Union[Sequence, LoaderVariants, Mapping]], Tuple, LoaderVariants
    ],
    id_type: str,
    eformat: Union[str, None] = None,
)

Source from the content-addressed store, hash-verified

341
342
343def normalize_parameter_edges(
344 edges: Union[
345 Mapping[str, Union[Sequence, LoaderVariants, Mapping]], Tuple, LoaderVariants
346 ],
347 id_type: str,
348 eformat: Union[str, None] = None,
349):
350 """Normalize parameters user passed in. Since parameters are very flexible, we need to be
351 careful about it.
352
353 Args:
354 edges (Union[ Mapping[str, Union[Sequence, LoaderVariants, Mapping]], Tuple, LoaderVariants ]):
355 Edges definition.
356 id_type (str): Type of vertex original id.
357 """
358
359 def process_sub_label(items):
360 if isinstance(items, (Loader, str, pd.DataFrame, *VineyardObjectTypes)):
361 return EdgeSubLabel(
362 items, None, "_", "_", 0, 1, id_type=id_type, eformat=eformat
363 )
364 elif isinstance(items, Sequence):
365 if all([isinstance(item, np.ndarray) for item in items]):
366 return EdgeSubLabel(
367 items, None, "_", "_", 0, 1, id_type=id_type, eformat=eformat
368 )
369 else:
370 check_argument(len(items) < 6, "Too many arguments for a edge label")
371 compat_items = _convert_array_to_deprecated_form(items)
372 return EdgeSubLabel(*compat_items, id_type=id_type, eformat=eformat)
373 elif isinstance(items, Mapping):
374 items = _convert_dict_to_compat_form(items)
375 return EdgeSubLabel(**items, id_type=id_type, eformat=eformat)
376 else:
377 raise SyntaxError("Wrong format of e sub label: " + str(items))
378
379 def process_label(label, items):
380 e_label = EdgeLabel(label, id_type)
381 if isinstance(items, (Loader, str, pd.DataFrame, *VineyardObjectTypes)):
382 e_label.add_sub_label(process_sub_label(items))
383 elif isinstance(items, Sequence):
384 if isinstance(
385 items[0], (Loader, str, pd.DataFrame, *VineyardObjectTypes, np.ndarray)
386 ):
387 e_label.add_sub_label(process_sub_label(items))
388 else:
389 for item in items:
390 e_label.add_sub_label(process_sub_label(item))
391 elif isinstance(items, Mapping):
392 e_label.add_sub_label(process_sub_label(items))
393 else:
394 raise SyntaxError("Wrong format of e label: " + str(items))
395 return e_label
396
397 e_labels = []
398 if edges is None:
399 raise ValueError("Edges should be None")
400 if isinstance(edges, Mapping):

Callers 2

load_fromFunction · 0.90
load_subgraphMethod · 0.90

Calls 3

process_labelFunction · 0.85
itemsMethod · 0.80
appendMethod · 0.65

Tested by

no test coverage detected