Hashir621 commited on
Commit
d554fd2
·
verified ·
1 Parent(s): db89cb3

Use native timestamps, booleans, integers, and nulls for subreddit metadata

Browse files
Files changed (4) hide show
  1. README.md +15 -23
  2. conversion-manifest.json +31 -10
  3. convert.py +92 -12
  4. data/data.parquet +2 -2
README.md CHANGED
@@ -27,19 +27,19 @@ dataset_info:
27
  - name: display_name
28
  dtype: string
29
  - name: created_utc
30
- dtype: string
31
  - name: over18
32
- dtype: string
33
  - name: url
34
  dtype: string
35
  - name: subscribers
36
- dtype: string
37
  - name: public_description
38
  dtype: string
39
  - name: subreddit
40
  dtype: string
41
  - name: retrieved_on
42
- dtype: string
43
  - name: rules_markdown
44
  dtype: string
45
  - name: descp
@@ -47,10 +47,10 @@ dataset_info:
47
  config_name: default
48
  splits:
49
  - name: data
50
- num_bytes: 409798485
51
  num_examples: 395018
52
- download_size: 183178103
53
- dataset_size: 409798485
54
  ---
55
 
56
  # Subreddits Directory
@@ -61,30 +61,26 @@ The dataset contains **395,018 rows and 12 columns** of subreddit names, descrip
61
 
62
  **This dataset contains historical metadata.** The publication date of this repository is not the collection date. Names, descriptions, member counts, rules, availability, and other values reflect previously collected records. Where available, `retrieved_on` provides a record's retrieval timestamp. This is not a verified directory of every currently existing subreddit.
63
 
64
- ## Data and preservation
65
 
66
- The single file `data/data.parquet` uses Zstandard compression and is 183,178,103 bytes (approximately 183 MB). The `data` split contains the entire table. It is a general-purpose directory of subreddit metadata, with no predefined task or evaluation partition.
67
 
68
- All original column names, parsed cell values, row order, and column order are preserved. No rows were filtered, deduplicated, added, or reordered. No descriptions were rewritten, combined, trimmed, or filled in. Existing rules and other auxiliary columns are retained.
69
-
70
- Every column is stored as a **string**, including counts, booleans, and timestamps. This deliberately avoids changing numeric spellings, boolean spellings, or timestamp representations during CSV type inference. Empty CSV cells remain empty strings, not nulls. CSV quoting and delimiters are serialization details and are replaced by Parquet encoding.
71
-
72
- The conversion was verified by comparing **every cell of every row** with the original records. `conversion-manifest.json` records the validation result, file SHA-256 checksums, schema, and empty-string counts. The Parquet file contains the complete published table and can be used independently.
73
 
74
  ## Columns
75
 
76
- | Column | Meaning | Empty cells |
77
  |---|---|---:|
78
  | `title` | Subreddit title. | 18 |
79
  | `description` | Longer subreddit description/sidebar text. | 161,178 |
80
  | `display_name` | Subreddit display name. | 1 |
81
- | `created_utc` | Community creation-time value in its original representation. | 0 |
82
- | `over18` | Adult-content/NSFW flag, retained as text. | 0 |
83
  | `url` | Community URL or relative Reddit path. | 0 |
84
- | `subscribers` | Subscriber/member count at collection time, retained as text. | 0 |
85
  | `public_description` | Short public subreddit description. | 54,126 |
86
  | `subreddit` | Subreddit name. | 0 |
87
- | `retrieved_on` | Retrieval-time value, when provided; retained verbatim. | 259,611 |
88
  | `rules_markdown` | Community rules in Markdown, when provided. | 259,611 |
89
  | `descp` | Auxiliary description field. Its original construction is undocumented; it is preserved without reinterpretation. | 0 |
90
 
@@ -107,8 +103,6 @@ dataset = load_dataset(
107
  row = next(iter(dataset))
108
  ```
109
 
110
- Consumers can explicitly parse numeric or date columns for their own analysis. No such coercion is applied to the published data.
111
-
112
  ## Download the Parquet file
113
 
114
  Download directly from this repository with the Hugging Face CLI:
@@ -117,8 +111,6 @@ Download directly from this repository with the Hugging Face CLI:
117
  hf download semvec/subreddits-directory data/data.parquet --repo-type dataset --local-dir subreddits-directory
118
  ```
119
 
120
- The repository also includes `convert.py`, the CSV-to-Parquet conversion and validation script used to prepare this edition. It is not needed to load or download the dataset.
121
-
122
  ## Usage terms and limitations
123
 
124
  The full original collection methodology is not documented. Community flags and metadata have not been independently validated, and completeness is not guaranteed.
 
27
  - name: display_name
28
  dtype: string
29
  - name: created_utc
30
+ dtype: timestamp[us, tz=UTC]
31
  - name: over18
32
+ dtype: bool
33
  - name: url
34
  dtype: string
35
  - name: subscribers
36
+ dtype: int64
37
  - name: public_description
38
  dtype: string
39
  - name: subreddit
40
  dtype: string
41
  - name: retrieved_on
42
+ dtype: timestamp[us, tz=UTC]
43
  - name: rules_markdown
44
  dtype: string
45
  - name: descp
 
47
  config_name: default
48
  splits:
49
  - name: data
50
+ num_bytes: 400524343
51
  num_examples: 395018
52
+ download_size: 184146598
53
+ dataset_size: 400524343
54
  ---
55
 
56
  # Subreddits Directory
 
61
 
62
  **This dataset contains historical metadata.** The publication date of this repository is not the collection date. Names, descriptions, member counts, rules, availability, and other values reflect previously collected records. Where available, `retrieved_on` provides a record's retrieval timestamp. This is not a verified directory of every currently existing subreddit.
63
 
64
+ ## Dataset contents
65
 
66
+ Each record describes a Reddit community through its name, title, descriptions, member count, creation and retrieval dates, adult-content flag, and available rules. The `data` split contains the complete directory.
67
 
68
+ All original records and columns are retained in their original order. Descriptions and rules have not been rewritten, and no metadata has been refreshed. Missing values and any duplicate records remain part of the dataset.
 
 
 
 
69
 
70
  ## Columns
71
 
72
+ | Column | Meaning | Missing values |
73
  |---|---|---:|
74
  | `title` | Subreddit title. | 18 |
75
  | `description` | Longer subreddit description/sidebar text. | 161,178 |
76
  | `display_name` | Subreddit display name. | 1 |
77
+ | `created_utc` | When the community was created (UTC). | 0 |
78
+ | `over18` | Whether the community is marked as adult content/NSFW. | 0 |
79
  | `url` | Community URL or relative Reddit path. | 0 |
80
+ | `subscribers` | Subscriber/member count at collection time. | 0 |
81
  | `public_description` | Short public subreddit description. | 54,126 |
82
  | `subreddit` | Subreddit name. | 0 |
83
+ | `retrieved_on` | When the metadata was retrieved (UTC), where available. | 259,611 |
84
  | `rules_markdown` | Community rules in Markdown, when provided. | 259,611 |
85
  | `descp` | Auxiliary description field. Its original construction is undocumented; it is preserved without reinterpretation. | 0 |
86
 
 
103
  row = next(iter(dataset))
104
  ```
105
 
 
 
106
  ## Download the Parquet file
107
 
108
  Download directly from this repository with the Hugging Face CLI:
 
111
  hf download semvec/subreddits-directory data/data.parquet --repo-type dataset --local-dir subreddits-directory
112
  ```
113
 
 
 
114
  ## Usage terms and limitations
115
 
116
  The full original collection methodology is not documented. Community flags and metadata have not been independently validated, and completeness is not guaranteed.
conversion-manifest.json CHANGED
@@ -5,8 +5,8 @@
5
  "source_sha256": "a449ece09a2115e8eba670a0d00cc0cca734b4b3d85d289dcd5f6f2becd833b1",
6
  "source_license_identifier": "reddit-api",
7
  "parquet_file": "data/data.parquet",
8
- "parquet_bytes": 183178103,
9
- "parquet_sha256": "20cd09b4fed1c12bd316574c43a0ebaae0beb27b75c74d58c1057eb2104a0746",
10
  "row_count": 395018,
11
  "column_count": 12,
12
  "columns": [
@@ -27,17 +27,31 @@
27
  "title": "string",
28
  "description": "string",
29
  "display_name": "string",
30
- "created_utc": "string",
31
- "over18": "string",
32
  "url": "string",
33
- "subscribers": "string",
34
  "public_description": "string",
35
  "subreddit": "string",
36
- "retrieved_on": "string",
37
  "rules_markdown": "string",
38
  "descp": "string"
39
  },
40
- "empty_string_counts": {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  "title": 18,
42
  "description": 161178,
43
  "display_name": 1,
@@ -52,9 +66,11 @@
52
  "descp": 0
53
  },
54
  "validation": {
55
- "method": "Full row-by-row and cell-by-cell comparison with parsed source CSV",
56
  "verified_rows": 395018,
57
- "all_values_identical": true,
 
 
58
  "row_order_preserved": true,
59
  "column_order_preserved": true
60
  },
@@ -63,7 +79,12 @@
63
  "compression": "zstd",
64
  "csv_encoding": "utf-8",
65
  "type_inference": false,
66
- "empty_fields": "Preserved as empty strings; no null inference",
 
 
 
 
 
67
  "metadata_refreshed": false
68
  }
69
  }
 
5
  "source_sha256": "a449ece09a2115e8eba670a0d00cc0cca734b4b3d85d289dcd5f6f2becd833b1",
6
  "source_license_identifier": "reddit-api",
7
  "parquet_file": "data/data.parquet",
8
+ "parquet_bytes": 184146598,
9
+ "parquet_sha256": "c8a520b2d2785cf79c9baa23ba98f904e5bee2e146acb6ff9b20aa345ddddb68",
10
  "row_count": 395018,
11
  "column_count": 12,
12
  "columns": [
 
27
  "title": "string",
28
  "description": "string",
29
  "display_name": "string",
30
+ "created_utc": "timestamp[us, tz=UTC]",
31
+ "over18": "bool",
32
  "url": "string",
33
+ "subscribers": "int64",
34
  "public_description": "string",
35
  "subreddit": "string",
36
+ "retrieved_on": "timestamp[us, tz=UTC]",
37
  "rules_markdown": "string",
38
  "descp": "string"
39
  },
40
+ "source_empty_string_counts": {
41
+ "title": 18,
42
+ "description": 161178,
43
+ "display_name": 1,
44
+ "created_utc": 0,
45
+ "over18": 0,
46
+ "url": 0,
47
+ "subscribers": 0,
48
+ "public_description": 54126,
49
+ "subreddit": 0,
50
+ "retrieved_on": 259611,
51
+ "rules_markdown": 259611,
52
+ "descp": 0
53
+ },
54
+ "null_counts": {
55
  "title": 18,
56
  "description": 161178,
57
  "display_name": 1,
 
66
  "descp": 0
67
  },
68
  "validation": {
69
+ "method": "Full cell-by-cell comparison: exact nonempty text, inverse semantic comparisons for typed values, empty cells mapped to null",
70
  "verified_rows": 395018,
71
+ "all_semantic_values_match": true,
72
+ "nonempty_text_unchanged": true,
73
+ "null_counts_match_source_empty_cells": true,
74
  "row_order_preserved": true,
75
  "column_order_preserved": true
76
  },
 
79
  "compression": "zstd",
80
  "csv_encoding": "utf-8",
81
  "type_inference": false,
82
+ "empty_fields": "Only exact empty strings become null; literal null-like text is preserved",
83
+ "created_utc": "ISO 8601 UTC to timestamp[us, tz=UTC]",
84
+ "retrieved_on": "Unix seconds to timestamp[us, tz=UTC] using exact decimal arithmetic",
85
+ "over18": "True/False text to boolean",
86
+ "subscribers": "Nonnegative integer text to int64",
87
+ "write_page_index": true,
88
  "metadata_refreshed": false
89
  }
90
  }
convert.py CHANGED
@@ -1,7 +1,7 @@
1
- """Losslessly convert the source CSV's parsed cells to Parquet.
2
 
3
  Usage: python convert.py path/to/subreddits_with_details.csv output_directory
4
- Requires pyarrow. No Reddit requests, cleanup, filtering, or type inference.
5
  """
6
 
7
  import csv
@@ -9,11 +9,70 @@ import hashlib
9
  import itertools
10
  import json
11
  import sys
 
 
12
  from pathlib import Path
13
 
14
  import pyarrow as pa
15
  import pyarrow.parquet as pq
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  def sha256(path):
19
  with path.open("rb") as stream:
@@ -30,31 +89,44 @@ def convert(source, output):
30
  reader = csv.reader(stream, strict=True)
31
  columns = next(reader)
32
  assert len(set(columns)) == len(columns), "Duplicate source column names"
33
- schema = pa.schema([(name, pa.string()) for name in columns])
34
  empty_counts = dict.fromkeys(columns, 0)
35
- with pq.ParquetWriter(target, schema, compression="zstd") as writer:
36
  while rows := list(itertools.islice(reader, 5000)):
37
  assert all(len(row) == len(columns) for row in rows), "Ragged CSV row"
38
  arrays = []
39
  for index, name in enumerate(columns):
40
  values = [row[index] for row in rows]
41
  empty_counts[name] += values.count("")
42
- arrays.append(pa.array(values, type=pa.string()))
 
 
 
43
  writer.write_table(pa.Table.from_arrays(arrays, schema=schema))
44
  row_count += len(rows)
45
 
46
  # Independently read the original CSV again and compare every output cell.
47
  verified_rows = 0
 
 
 
48
  with source.open(encoding="utf-8", newline="") as stream:
49
  reader = csv.reader(stream, strict=True)
50
  assert next(reader) == columns
51
- for batch in pq.ParquetFile(target).iter_batches(batch_size=5000):
52
  assert batch.schema.names == columns
 
 
53
  for row in zip(*(column.to_pylist() for column in batch.columns)):
54
- assert list(row) == next(reader), f"Mismatch at row {verified_rows}"
 
 
 
 
55
  verified_rows += 1
56
  assert next(reader, None) is None, "Source has additional rows"
57
  assert verified_rows == row_count
 
58
 
59
  manifest = {
60
  "source": "https://www.kaggle.com/datasets/hashiromer/subreddits-directory",
@@ -68,12 +140,15 @@ def convert(source, output):
68
  "row_count": row_count,
69
  "column_count": len(columns),
70
  "columns": columns,
71
- "column_types": dict.fromkeys(columns, "string"),
72
- "empty_string_counts": empty_counts,
 
73
  "validation": {
74
- "method": "Full row-by-row and cell-by-cell comparison with parsed source CSV",
75
  "verified_rows": verified_rows,
76
- "all_values_identical": True,
 
 
77
  "row_order_preserved": True,
78
  "column_order_preserved": True,
79
  },
@@ -82,7 +157,12 @@ def convert(source, output):
82
  "compression": "zstd",
83
  "csv_encoding": "utf-8",
84
  "type_inference": False,
85
- "empty_fields": "Preserved as empty strings; no null inference",
 
 
 
 
 
86
  "metadata_refreshed": False,
87
  },
88
  }
 
1
+ """Convert subreddit metadata to Parquet with explicit semantic types.
2
 
3
  Usage: python convert.py path/to/subreddits_with_details.csv output_directory
4
+ Requires pyarrow. No Reddit requests, filtering, or metadata refresh.
5
  """
6
 
7
  import csv
 
9
  import itertools
10
  import json
11
  import sys
12
+ from datetime import datetime, timedelta, timezone
13
+ from decimal import Decimal
14
  from pathlib import Path
15
 
16
  import pyarrow as pa
17
  import pyarrow.parquet as pq
18
 
19
+ EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)
20
+ TIMESTAMP = pa.timestamp("us", tz="UTC")
21
+ TYPES = {
22
+ "created_utc": TIMESTAMP,
23
+ "retrieved_on": TIMESTAMP,
24
+ "over18": pa.bool_(),
25
+ "subscribers": pa.int64(),
26
+ }
27
+
28
+
29
+ def parse_cell(name, value):
30
+ if value == "":
31
+ return None
32
+ if name == "created_utc":
33
+ parsed = datetime.fromisoformat(value.replace("Z", "+00:00"))
34
+ if parsed.tzinfo is None:
35
+ raise ValueError(f"Creation timestamp lacks timezone: {value!r}")
36
+ return parsed.astimezone(timezone.utc)
37
+ if name == "retrieved_on":
38
+ micros = Decimal(value) * 1_000_000
39
+ if not micros.is_finite() or micros != micros.to_integral_value():
40
+ raise ValueError(f"Invalid or sub-microsecond retrieval timestamp: {value!r}")
41
+ return EPOCH + timedelta(microseconds=int(micros))
42
+ if name == "over18":
43
+ if value not in ("True", "False"):
44
+ raise ValueError(f"Unexpected boolean: {value!r}")
45
+ return value == "True"
46
+ if name == "subscribers":
47
+ if not value.isascii() or not value.isdecimal():
48
+ raise ValueError(f"Invalid subscriber count: {value!r}")
49
+ return int(value)
50
+ return value
51
+
52
+
53
+ def verify_cell(name, original, converted):
54
+ """Check output against source using inverse semantic comparisons."""
55
+ if original == "":
56
+ return converted is None
57
+ if converted is None:
58
+ return False
59
+ if name == "created_utc":
60
+ # The source uses either minute or second precision, always UTC.
61
+ return original in (
62
+ converted.strftime("%Y-%m-%dT%H:%M:%SZ"),
63
+ converted.strftime("%Y-%m-%dT%H:%MZ")
64
+ if converted.second == converted.microsecond == 0 else "",
65
+ ) and converted.utcoffset() == timedelta(0)
66
+ if name == "retrieved_on":
67
+ delta = converted - EPOCH
68
+ micros = (delta.days * 86400 + delta.seconds) * 1_000_000 + delta.microseconds
69
+ return Decimal(micros) / 1_000_000 == Decimal(original)
70
+ if name == "over18":
71
+ return type(converted) is bool and str(converted) == original
72
+ if name == "subscribers":
73
+ return type(converted) is int and Decimal(converted) == Decimal(original)
74
+ return converted == original
75
+
76
 
77
  def sha256(path):
78
  with path.open("rb") as stream:
 
89
  reader = csv.reader(stream, strict=True)
90
  columns = next(reader)
91
  assert len(set(columns)) == len(columns), "Duplicate source column names"
92
+ schema = pa.schema([(name, TYPES.get(name, pa.string())) for name in columns])
93
  empty_counts = dict.fromkeys(columns, 0)
94
+ with pq.ParquetWriter(target, schema, compression="zstd", write_page_index=True) as writer:
95
  while rows := list(itertools.islice(reader, 5000)):
96
  assert all(len(row) == len(columns) for row in rows), "Ragged CSV row"
97
  arrays = []
98
  for index, name in enumerate(columns):
99
  values = [row[index] for row in rows]
100
  empty_counts[name] += values.count("")
101
+ arrays.append(pa.array(
102
+ [parse_cell(name, value) for value in values],
103
+ type=schema.field(name).type,
104
+ ))
105
  writer.write_table(pa.Table.from_arrays(arrays, schema=schema))
106
  row_count += len(rows)
107
 
108
  # Independently read the original CSV again and compare every output cell.
109
  verified_rows = 0
110
+ null_counts = dict.fromkeys(columns, 0)
111
+ parquet = pq.ParquetFile(target)
112
+ assert parquet.schema_arrow.equals(schema), "Parquet schema mismatch"
113
  with source.open(encoding="utf-8", newline="") as stream:
114
  reader = csv.reader(stream, strict=True)
115
  assert next(reader) == columns
116
+ for batch in parquet.iter_batches(batch_size=5000):
117
  assert batch.schema.names == columns
118
+ for name, array in zip(columns, batch.columns):
119
+ null_counts[name] += array.null_count
120
  for row in zip(*(column.to_pylist() for column in batch.columns)):
121
+ original = next(reader)
122
+ assert all(
123
+ verify_cell(name, old, new)
124
+ for name, old, new in zip(columns, original, row)
125
+ ), f"Mismatch at row {verified_rows}"
126
  verified_rows += 1
127
  assert next(reader, None) is None, "Source has additional rows"
128
  assert verified_rows == row_count
129
+ assert null_counts == empty_counts, "Null counts differ from source empty cells"
130
 
131
  manifest = {
132
  "source": "https://www.kaggle.com/datasets/hashiromer/subreddits-directory",
 
140
  "row_count": row_count,
141
  "column_count": len(columns),
142
  "columns": columns,
143
+ "column_types": {field.name: str(field.type) for field in schema},
144
+ "source_empty_string_counts": empty_counts,
145
+ "null_counts": null_counts,
146
  "validation": {
147
+ "method": "Full cell-by-cell comparison: exact nonempty text, inverse semantic comparisons for typed values, empty cells mapped to null",
148
  "verified_rows": verified_rows,
149
+ "all_semantic_values_match": True,
150
+ "nonempty_text_unchanged": True,
151
+ "null_counts_match_source_empty_cells": True,
152
  "row_order_preserved": True,
153
  "column_order_preserved": True,
154
  },
 
157
  "compression": "zstd",
158
  "csv_encoding": "utf-8",
159
  "type_inference": False,
160
+ "empty_fields": "Only exact empty strings become null; literal null-like text is preserved",
161
+ "created_utc": "ISO 8601 UTC to timestamp[us, tz=UTC]",
162
+ "retrieved_on": "Unix seconds to timestamp[us, tz=UTC] using exact decimal arithmetic",
163
+ "over18": "True/False text to boolean",
164
+ "subscribers": "Nonnegative integer text to int64",
165
+ "write_page_index": True,
166
  "metadata_refreshed": False,
167
  },
168
  }
data/data.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:20cd09b4fed1c12bd316574c43a0ebaae0beb27b75c74d58c1057eb2104a0746
3
- size 183178103
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c8a520b2d2785cf79c9baa23ba98f904e5bee2e146acb6ff9b20aa345ddddb68
3
+ size 184146598