We read all data which is specified as UTF-8 encoded using the
utf-8-sig codecs.
Thus, if such data starts with U+FEFF this will be interpreted as BOM
and skipped.
Low level CSV parsing is delegated to the csv module in Python's standard library. Thus, if a commentPrefix
is specified in a Dialect instance, this will lead to skipping rows where the first value starts
with commentPrefix, even if the value was quoted.
Also, cell content containing escapechar may not be round-tripped as expected (when specifying
escapechar or a csvw.Dialect with quoteChar but doubleQuote==False),
when minimal quoting is specified. This is due to inconsistent csv behaviour
across Python versions (see https://bugs.python.org/issue44861).
CSVW conformance
While we use the CSVW specification as guideline, this package does not (and
probably never will) implement the full extent of this spec.
When CSV files with a header are read, columns are not matched in order with
column descriptions in the tableSchema, but instead are matched based on the
CSV column header and the column descriptions' name and titles atributes.
This allows for more flexibility, because columns in the CSV file may be
re-ordered without invalidating the metadata. A stricter matching can be forced
by specifying "header": false and "skipRows": 1 in the table's dialect
description.
A CSVW-described dataset is basically equivalent to a Frictionless DataPackage where all
Data Resources are Tabular Data.
Thus, the csvw package provides some conversion functionality. To
"read CSVW data from a Data Package", there's the csvw.TableGroup.from_frictionless_datapackage method:
from csvw import TableGroup
tg = TableGroup.from_frictionless_datapackage('PATH/TO/datapackage.json')
To convert the metadata, the TableGroup can then be serialzed:
tg.to_file('csvw-metadata.json')
Note that the CSVW metadata file must be written to the Data Package's directory
to make sure relative paths to data resources work.
This functionality - together with the schema inference capabilities
of frictionless describe - provides
a convenient way to bootstrap CSVW metadata for a set of "raw" CSV
files, implemented in the csvwdescribe command described above.