Use native timestamps, booleans, integers, and nulls for subreddit metadata
Browse filesFiles changed (4)
- README.md+15-23
- conversion-manifest.json+31-10
- convert.py+92-12
- data/data.parquet+2-2
26 unmodified lines27282930303132323334353636373839404142424344451 unmodified line474849505051525352535455564 unmodified lines616263646465666667686970717268697071767273747576818277787984808182878384858616 unmodified lines1031041051101111061071082 unmodified lines11111211312012111411511626 unmodified lines - name: display_name dtype: string - name: created_utc dtype: string dtype: timestamp[us, tz=UTC] - name: over18 dtype: string dtype: bool - name: url dtype: string - name: subscribers dtype: string dtype: int64 - name: public_description dtype: string - name: subreddit dtype: string - name: retrieved_on dtype: string dtype: timestamp[us, tz=UTC] - name: rules_markdown dtype: string - name: descp1 unmodified line config_name: default splits: - name: data num_bytes: 409798485 num_bytes: 400524343 num_examples: 395018 download_size: 183178103 dataset_size: 409798485 download_size: 184146598 dataset_size: 400524343---
# Subreddits Directory4 unmodified lines
**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.
## Data and preservation## Dataset contents
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.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.
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.
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.
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.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.
## Columns
| Column | Meaning | Empty cells || Column | Meaning | Missing values ||---|---|---:|| `title` | Subreddit title. | 18 || `description` | Longer subreddit description/sidebar text. | 161,178 || `display_name` | Subreddit display name. | 1 || `created_utc` | Community creation-time value in its original representation. | 0 || `over18` | Adult-content/NSFW flag, retained as text. | 0 || `created_utc` | When the community was created (UTC). | 0 || `over18` | Whether the community is marked as adult content/NSFW. | 0 || `url` | Community URL or relative Reddit path. | 0 || `subscribers` | Subscriber/member count at collection time, retained as text. | 0 || `subscribers` | Subscriber/member count at collection time. | 0 || `public_description` | Short public subreddit description. | 54,126 || `subreddit` | Subreddit name. | 0 || `retrieved_on` | Retrieval-time value, when provided; retained verbatim. | 259,611 || `retrieved_on` | When the metadata was retrieved (UTC), where available. | 259,611 || `rules_markdown` | Community rules in Markdown, when provided. | 259,611 || `descp` | Auxiliary description field. Its original construction is undocumented; it is preserved without reinterpretation. | 0 |
16 unmodified linesrow = next(iter(dataset))```
Consumers can explicitly parse numeric or date columns for their own analysis. No such coercion is applied to the published data.
## Download the Parquet file
Download directly from this repository with the Hugging Face CLI:2 unmodified lineshf download semvec/subreddits-directory data/data.parquet --repo-type dataset --local-dir subreddits-directory```
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.
## Usage terms and limitations
The full original collection methodology is not documented. Community flags and metadata have not been independently validated, and completeness is not guaranteed.4 unmodified lines567898910111214 unmodified lines2728293031303132333334353636373839404041424344454647484950515253545556578 unmodified lines666768556970577172737475762 unmodified lines798081668283848586878889904 unmodified lines "source_sha256": "a449ece09a2115e8eba670a0d00cc0cca734b4b3d85d289dcd5f6f2becd833b1", "source_license_identifier": "reddit-api", "parquet_file": "data/data.parquet", "parquet_bytes": 183178103, "parquet_sha256": "20cd09b4fed1c12bd316574c43a0ebaae0beb27b75c74d58c1057eb2104a0746", "parquet_bytes": 184146598, "parquet_sha256": "c8a520b2d2785cf79c9baa23ba98f904e5bee2e146acb6ff9b20aa345ddddb68", "row_count": 395018, "column_count": 12, "columns": [14 unmodified lines "title": "string", "description": "string", "display_name": "string", "created_utc": "string", "over18": "string", "created_utc": "timestamp[us, tz=UTC]", "over18": "bool", "url": "string", "subscribers": "string", "subscribers": "int64", "public_description": "string", "subreddit": "string", "retrieved_on": "string", "retrieved_on": "timestamp[us, tz=UTC]", "rules_markdown": "string", "descp": "string" }, "empty_string_counts": { "source_empty_string_counts": { "title": 18, "description": 161178, "display_name": 1, "created_utc": 0, "over18": 0, "url": 0, "subscribers": 0, "public_description": 54126, "subreddit": 0, "retrieved_on": 259611, "rules_markdown": 259611, "descp": 0 }, "null_counts": { "title": 18, "description": 161178, "display_name": 1,8 unmodified lines "descp": 0 }, "validation": { "method": "Full row-by-row and cell-by-cell comparison with parsed source CSV", "method": "Full cell-by-cell comparison: exact nonempty text, inverse semantic comparisons for typed values, empty cells mapped to null", "verified_rows": 395018, "all_values_identical": true, "all_semantic_values_match": true, "nonempty_text_unchanged": true, "null_counts_match_source_empty_cells": true, "row_order_preserved": true, "column_order_preserved": true },2 unmodified lines "compression": "zstd", "csv_encoding": "utf-8", "type_inference": false, "empty_fields": "Preserved as empty strings; no null inference", "empty_fields": "Only exact empty strings become null; literal null-like text is preserved", "created_utc": "ISO 8601 UTC to timestamp[us, tz=UTC]", "retrieved_on": "Unix seconds to timestamp[us, tz=UTC] using exact decimal arithmetic", "over18": "True/False text to boolean", "subscribers": "Nonnegative integer text to int64", "write_page_index": true, "metadata_refreshed": false }}1123445671 unmodified line910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777810 unmodified lines899091339293359495969798991004210110210310410510610710810911011111211311411551116117118119120121122123124541251261271281291301311327 unmodified lines140141142717214314414514674147148761491501511521531542 unmodified lines15715815985160161162163164165166167168"""Losslessly convert the source CSV's parsed cells to Parquet."""Convert subreddit metadata to Parquet with explicit semantic types.
Usage: python convert.py path/to/subreddits_with_details.csv output_directoryRequires pyarrow. No Reddit requests, cleanup, filtering, or type inference.Requires pyarrow. No Reddit requests, filtering, or metadata refresh."""
import csv1 unmodified lineimport itertoolsimport jsonimport sysfrom datetime import datetime, timedelta, timezonefrom decimal import Decimalfrom pathlib import Path
import pyarrow as paimport pyarrow.parquet as pq
EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)TIMESTAMP = pa.timestamp("us", tz="UTC")TYPES = { "created_utc": TIMESTAMP, "retrieved_on": TIMESTAMP, "over18": pa.bool_(), "subscribers": pa.int64(),}
def parse_cell(name, value): if value == "": return None if name == "created_utc": parsed = datetime.fromisoformat(value.replace("Z", "+00:00")) if parsed.tzinfo is None: raise ValueError(f"Creation timestamp lacks timezone: {value!r}") return parsed.astimezone(timezone.utc) if name == "retrieved_on": micros = Decimal(value) * 1_000_000 if not micros.is_finite() or micros != micros.to_integral_value(): raise ValueError(f"Invalid or sub-microsecond retrieval timestamp: {value!r}") return EPOCH + timedelta(microseconds=int(micros)) if name == "over18": if value not in ("True", "False"): raise ValueError(f"Unexpected boolean: {value!r}") return value == "True" if name == "subscribers": if not value.isascii() or not value.isdecimal(): raise ValueError(f"Invalid subscriber count: {value!r}") return int(value) return value
def verify_cell(name, original, converted): """Check output against source using inverse semantic comparisons.""" if original == "": return converted is None if converted is None: return False if name == "created_utc": # The source uses either minute or second precision, always UTC. return original in ( converted.strftime("%Y-%m-%dT%H:%M:%SZ"), converted.strftime("%Y-%m-%dT%H:%MZ") if converted.second == converted.microsecond == 0 else "", ) and converted.utcoffset() == timedelta(0) if name == "retrieved_on": delta = converted - EPOCH micros = (delta.days * 86400 + delta.seconds) * 1_000_000 + delta.microseconds return Decimal(micros) / 1_000_000 == Decimal(original) if name == "over18": return type(converted) is bool and str(converted) == original if name == "subscribers": return type(converted) is int and Decimal(converted) == Decimal(original) return converted == original
def sha256(path): with path.open("rb") as stream:10 unmodified lines reader = csv.reader(stream, strict=True) columns = next(reader) assert len(set(columns)) == len(columns), "Duplicate source column names" schema = pa.schema([(name, pa.string()) for name in columns]) schema = pa.schema([(name, TYPES.get(name, pa.string())) for name in columns]) empty_counts = dict.fromkeys(columns, 0) with pq.ParquetWriter(target, schema, compression="zstd") as writer: with pq.ParquetWriter(target, schema, compression="zstd", write_page_index=True) as writer: while rows := list(itertools.islice(reader, 5000)): assert all(len(row) == len(columns) for row in rows), "Ragged CSV row" arrays = [] for index, name in enumerate(columns): values = [row[index] for row in rows] empty_counts[name] += values.count("") arrays.append(pa.array(values, type=pa.string())) arrays.append(pa.array( [parse_cell(name, value) for value in values], type=schema.field(name).type, )) writer.write_table(pa.Table.from_arrays(arrays, schema=schema)) row_count += len(rows)
# Independently read the original CSV again and compare every output cell. verified_rows = 0 null_counts = dict.fromkeys(columns, 0) parquet = pq.ParquetFile(target) assert parquet.schema_arrow.equals(schema), "Parquet schema mismatch" with source.open(encoding="utf-8", newline="") as stream: reader = csv.reader(stream, strict=True) assert next(reader) == columns for batch in pq.ParquetFile(target).iter_batches(batch_size=5000): for batch in parquet.iter_batches(batch_size=5000): assert batch.schema.names == columns for name, array in zip(columns, batch.columns): null_counts[name] += array.null_count for row in zip(*(column.to_pylist() for column in batch.columns)): original = next(reader) assert all( verify_cell(name, old, new) for name, old, new in zip(columns, original, row) assert list(row) == next(reader), f"Mismatch at row {verified_rows}" ), f"Mismatch at row {verified_rows}" verified_rows += 1 assert next(reader, None) is None, "Source has additional rows" assert verified_rows == row_count assert null_counts == empty_counts, "Null counts differ from source empty cells"
manifest = { "source": "https://www.kaggle.com/datasets/hashiromer/subreddits-directory",7 unmodified lines "row_count": row_count, "column_count": len(columns), "columns": columns, "column_types": dict.fromkeys(columns, "string"), "empty_string_counts": empty_counts, "column_types": {field.name: str(field.type) for field in schema}, "source_empty_string_counts": empty_counts, "null_counts": null_counts, "validation": { "method": "Full row-by-row and cell-by-cell comparison with parsed source CSV", "method": "Full cell-by-cell comparison: exact nonempty text, inverse semantic comparisons for typed values, empty cells mapped to null", "verified_rows": verified_rows, "all_values_identical": True, "all_semantic_values_match": True, "nonempty_text_unchanged": True, "null_counts_match_source_empty_cells": True, "row_order_preserved": True, "column_order_preserved": True, },2 unmodified lines "compression": "zstd", "csv_encoding": "utf-8", "type_inference": False, "empty_fields": "Preserved as empty strings; no null inference", "empty_fields": "Only exact empty strings become null; literal null-like text is preserved", "created_utc": "ISO 8601 UTC to timestamp[us, tz=UTC]", "retrieved_on": "Unix seconds to timestamp[us, tz=UTC] using exact decimal arithmetic", "over18": "True/False text to boolean", "subscribers": "Nonnegative integer text to int64", "write_page_index": True, "metadata_refreshed": False, }, }12323version https://git-lfs.github.com/spec/v1oid sha256:20cd09b4fed1c12bd316574c43a0ebaae0beb27b75c74d58c1057eb2104a0746size 183178103oid sha256:c8a520b2d2785cf79c9baa23ba98f904e5bee2e146acb6ff9b20aa345ddddb68size 184146598README.md+15-23
conversion-manifest.json+31-10
convert.py+92-12
data/data.parquet+2-2