pudl_diff.dataset
¶
Access to a PUDL Parquet dataset: its datapackage, tables, and provenance.
DatasetProvenance
¶
Bases: ReportModel
A PUDL dataset's own provenance, as recorded in its datapackage.json.
All fields are None when the dataset's descriptor doesn't have them
- e.g. an older build predating git provenance, or one where the git
lookup itself failed at build time.
Source code in src/pudl_diff/dataset.py
created = None
class-attribute
instance-attribute
¶
UTC ISO-8601 timestamp of when this dataset was built - distinct from the
report's own created, which is when the comparison
was run.
git_sha = None
class-attribute
instance-attribute
¶
The git commit SHA of the PUDL code that built the dataset.
git_tags = None
class-attribute
instance-attribute
¶
The git tags on that commit, e.g. release versions like v2026.1.0.
id = None
class-attribute
instance-attribute
¶
The dataset's build UUID.
NoTablesError
¶
PudlDiffDataset
¶
A PUDL Parquet dataset located at a root path, described by a datapackage.
Wraps a root directory (local or remote, e.g. an S3 bucket) containing one
<table_name>.parquet file per table and a datapackage descriptor.
Source code in src/pudl_diff/dataset.py
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
datapackage
property
¶
The parsed datapackage descriptor for this dataset.
__init__(root, descriptor_name=None, display_root=None)
¶
Initialize with the dataset's root path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
str | PathLike[str] | UPath
|
Path to the directory containing the Parquet files and the
datapackage descriptor. A local path is made absolute, with any
symlinks resolved, so that it doesn't depend on the working
directory. May be a local path or a remote path
(e.g. |
required |
descriptor_name
|
str | None
|
Filename of the datapackage descriptor within
|
None
|
display_root
|
str | None
|
The root to record in reports instead of |
None
|
Source code in src/pudl_diff/dataset.py
display_table_path(table_name)
¶
The path to table_name's Parquet file, as recorded in reports.
Like table_path(), but under display_root.
Source code in src/pudl_diff/dataset.py
field_names(table_name)
¶
The column names of table_name, in datapackage order.
get_resource(table_name)
¶
Return the datapackage resource descriptor for table_name.
Raises:
| Type | Description |
|---|---|
ValueError
|
if no resource with that name exists in the datapackage. |
Source code in src/pudl_diff/dataset.py
parquet_table_names()
¶
Names of all tables with a Parquet file directly in root.
Unlike table_names(), this lists the files actually present, so it
doesn't depend on the datapackage descriptor existing or being current
(common for local development outputs).
Source code in src/pudl_diff/dataset.py
primary_key(table_name)
¶
The primary key columns of table_name, or an empty list if none.
Read from this dataset's own datapackage descriptor if it's present,
readable, and lists table_name. Otherwise falls back on other metadata
(see fallback_primary_key()): PUDL's own if it's installed, or else
the last nightly build's datapackage. This matters for local development
outputs, which may lack a datapackage.json entirely, or have one that's
stale relative to the Parquet files actually sitting alongside it
(e.g. a $PUDL_OUTPUT/parquet assembled by materializing individual
assets across branches and sessions, rather than a single full ETL
run). This is a best-effort fallback, logged when it's used so it's not
silent: if the local output is stale enough that this table's primary key
has since changed, the fallback's definition may not exactly match the file.
If no primary key can be found anywhere, the table is treated as having none.
Source code in src/pudl_diff/dataset.py
provenance()
¶
This dataset's own build provenance, from its datapackage descriptor.
Fields the descriptor doesn't have are left None on the returned
DatasetProvenance, e.g. for a build predating git
provenance tracking.
Source code in src/pudl_diff/dataset.py
scan_table(table_name)
¶
Lazily scan table_name as a Polars LazyFrame.
Works for both local and remote (e.g. S3) roots. Remote reads use the
storage options (e.g. credentials, anon) configured on this
dataset's root path.
Source code in src/pudl_diff/dataset.py
table_bytes(table_name)
¶
Size in bytes of the Parquet file backing table_name.
Works for both local and remote (e.g. S3) roots.
table_names()
¶
table_path(table_name)
¶
Path to the Parquet file backing table_name.
Deterministic from root and table_name alone - doesn't
require the datapackage descriptor to exist or list this table, so
that a missing or incomplete datapackage.json (common for local
development outputs) doesn't block locating the file itself.
scan_table() will raise its own clear error if the file isn't
actually there.
Source code in src/pudl_diff/dataset.py
resolve_tables(left, right, table_names)
¶
Decide which tables to compare.
Returns:
| Type | Description |
|---|---|
list[str]
|
The tables to compare: those given, or else every table with a Parquet |
list[str]
|
file in both datasets. Then the tables found only in the left dataset and |
list[str]
|
those found only in the right dataset, both empty when tables are given. |
Raises:
| Type | Description |
|---|---|
NoTablesError
|
If no tables were given, and the datasets have none in common. |