File size: 3,533 Bytes
e30adeb
24b01fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e30adeb
24b01fe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
language:
- code
- en
tags:
- code
- python
- comprehension
- the-stack
pretty_name: Python Comprehension Statements 1K
size_categories:
- 1K<n<10K
task_categories:
- text-generation
- fill-mask
license: other
---

# Python Comprehension Statements 1K

This dataset contains 1,000 Python statements extracted from `bigcode/the-stack`
that include at least one Python comprehension expression:

- list comprehensions
- set comprehensions
- dict comprehensions
- generator expressions

Each row is a nearest enclosing Python statement around one or more
comprehension expressions, along with line number information and source
metadata copied from the original The Stack sample.

## Dataset Details

- **Dataset name:** `py_comprehension_statements_1k`
- **Rows:** 1,000
- **Split:** `train`
- **Source dataset:** `bigcode/the-stack`, Python subset
- **Extraction script:** `scripts/collect_stack_comprehension_statements.py`
- **Original local JSONL:** `outputs/the_stack_python_comprehension_statements.jsonl`

## Schema

| Field | Type | Description |
| --- | --- | --- |
| `index` | `int64` | Zero-based index of the streamed source sample. |
| `statement_id` | `int64` | Statement index within the source sample. |
| `statement` | `string` | Extracted Python statement containing a comprehension. |
| `lineno` | `int64` | Starting line number in the original source file. |
| `end_lineno` | `int64` | Ending line number in the original source file. |
| `comprehension_types` | `list[string]` | AST comprehension node types present in the statement. |
| `metadata.hexsha` | `string` | Source commit hash from The Stack metadata. |
| `metadata.max_stars_repo_name` | `string` | Repository name from The Stack metadata. |
| `metadata.max_stars_repo_path` | `string` | File path from The Stack metadata. |
| `metadata.lang` | `string` | Source language label. |

## Comprehension Type Counts

The `comprehension_types` field can contain multiple values for a single row.
Across the 1,000 rows, the type occurrences are:

| Type | Count |
| --- | ---: |
| `ListComp` | 754 |
| `GeneratorExp` | 181 |
| `DictComp` | 76 |
| `SetComp` | 9 |

## Usage

```python
from datasets import load_dataset

dataset = load_dataset("nexround/py_comprehension_statements_1k")
train = dataset["train"]

print(train[0]["statement"])
print(train[0]["comprehension_types"])
```

If you have the dataset saved locally with `datasets.save_to_disk`, use:

```python
from datasets import load_from_disk

dataset = load_from_disk("outputs/the_stack_python_comprehension_statements_hf_dataset")
```

## Construction

The extraction process streamed Python files from The Stack, parsed each source
file with Python's `ast` module, found `ListComp`, `SetComp`, `DictComp`, and
`GeneratorExp` nodes, and saved the nearest enclosing statement for each unique
statement span.

Rows that could not be parsed as Python source were skipped.

## Intended Uses

This dataset is intended for lightweight analysis and experimentation around
Python comprehension syntax, such as:

- inspecting comprehension usage patterns
- evaluating code models on comprehension-heavy snippets
- constructing small probes or prompts involving Python comprehensions

## Licensing

This is a derived sample from The Stack. The original source code snippets come
from many upstream repositories with varying licenses. Users should consult and
respect the licensing metadata and terms of the upstream The Stack dataset and
the original repositories when using or redistributing examples.