IntellAgents's picture
Add dataset card, schemas, provenance, extractor and loading examples
9c9fb17 verified
|
Raw History Blame Contribute Delete
1.71 kB

Per-file graph example

Install pyarrow, datasets, and huggingface_hub. Copy pypi_graphs.py next to your analysis script (or add this directory to PYTHONPATH). Pin a dataset commit SHA from the repository's commit history:

from pathlib import Path
import pyarrow.parquet as pq
from pypi_graphs import download_shard, load_graph, source_record

root = Path("pypi-graphs")
revision = "<dataset commit SHA>"
download_shard(0, root, revision=revision, include_source=True)
first = pq.ParquetFile(root / "data/files/train-00000-of-00064.parquet").read_row_group(0).slice(0, 1).to_pylist()[0]
graph = load_graph(root, 0, first["source_id"])
print(graph.file["package"], len(graph.nodes), len(graph.relationships))
print(source_record(root, graph.file)["code"][:200])

# These retain full candidate sets and resolution evidence:
relationships = graph.relationships
# This is an explicitly chosen, incomplete binary view:
pairs = list(graph.selected_pairs(include_local_calls=True))
texts = list(graph.embedding_records())

Read files.parse_status before deciding whether a graph is fully analyzed. Empty graphs can correspond to retained failures/skips. The one metadata-error file contains a partial definition hierarchy. Shard alignment means graph tables with the same number contain the same source-file partition, not the same row count.

For large-scale processing, scan batches/row groups instead of calling load_graph repeatedly: the small helper demonstrates joins and semantics, not a bulk training input pipeline. Relationships do not have an artificial native edge ID; a downstream edge-instance ID can be derived from a release-pinned row location or aggregation key.