goodtables-pandas-py
Warning: Not an official frictionlessdata package
This package reads and validates a Frictionless Data Tabular Data Package using pandas. It is about ~10x faster than the official frictionlessdata/frictionless-py, at the expense of higher memory usage.
Usage
pip install goodtables-pandas-py
import goodtables_pandas as goodtables
report = goodtables.validate(source='datapackage.json')
Implementation notes
Limitations
- Only fields of type
string,number,integer,boolean,date,datetime,year, andgeopointare currently supported. Other types can easily be supported with additionalparse_*functions inparse.py. - Memory use could be greatly minimized by reading, parsing, and checking tables in chunks (using
pandas.read_csv(chunksize=)), and storing only field values for unique and foreign key checks.
Uniqueness of null
Pandas chooses to treat missing values (null) as regular values, meaning that they are equal to themselves. How uniqueness is defined as a result is illustrated in the following examples.
| unique | not unique |
|---|---|
(1), (null) |
(1), (null), (null) |
(1, 1), (1, null) |
(1, 1), (1, null), (1, null) |
As the following script demonstrates, pandas considers the repeated rows (1, null) to be duplicates, and thus not unique.
import pandas
import numpy as np
pandas.DataFrame(dict(x=[1, 1, 1], y=[1, np.nan, np.nan])).duplicated()
0 False 1 False 2 True dtype: bool
Although this behavior matches some SQL implementations (namely Microsoft SQL Server), others (namely PostgreSQL and SQLite) choose to treat null as unique. See this dbfiddle.
Key constraints
primaryKey
Fields in primaryKey cannot contain missing values (equivalent to required: true).
See https://github.com/frictionlessdata/specs/issues/593.
uniqueKey
The uniqueKeys property provides support for one or more row uniqueness
constraints which, unlike primaryKey, do support null values. Uniqueness is determined as described above.
{
"uniqueKeys": [
["x", "y"],
["y", "z"]
]
}
See https://github.com/frictionlessdata/specs/issues/593.
foreignKey
The reference key of a foreignKey must meet the requirements of uniqueKey: it must be unique but can contain null. The local key must be present in the reference key, unless one of the fields is null.
| reference | local: valid | local: invalid |
|---|---|---|
(1) |
(1), (null) |
(2) |
(1), (null) |
(1), (null) |
(2) |
(1, 1) |
(1, 1), (1, null), (2, null) |
(1, 2) |
De-duplication of key constraints
To avoid duplicate key checks, the various key constraints are expanded as follows:
- Reference foreign keys (
foreignKey.reference.fields) are added (if not already present) to the unique keys (uniqueKeys) of the reference resource. TheforeignKeycheck only considers whether the local key is in the reference key. - The primary key (
primaryKey) is moved (if not already present) to the unique keys (uniqueKeys) and the fields in the key become required (field.constraints.required: true) if not already. - Single-field unique keys (
uniqueKeys) are dropped and the fields become unique (field.constraints.unique: true) if not already.
The following example illustrates the transformation in terms of Table Schema descriptor.
Original
{
"fields": [
{
"name": "x",
"required": true
},
{
"name": "y",
"required": true
},
{
"name": "x2"
}
],
"primaryKey": ["x", "y"],
"uniqueKeys": [
["x", "y"],
["x"]
],
"foreignKeys": [
{
"fields": ["x2"],
"reference": {
"resource": "",
"fields": ["x"]
}
}
]
}
Checked
{
"fields": [
{
"name": "x",
"required": true,
"unique": true
},
{
"name": "y",
"required": true
},
{
"name": "x2"
}
],
"uniqueKeys": [
["x", "y"]
],
"foreignKeys": [
{
"fields": ["x2"],
"reference": {
"resource": "",
"fields": ["x"]
}
}
]
}
Metadata
Release files for goodtables-pandas-py 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| goodtables-pandas-py-0.2.0.tar.gz | 16.6 kB | Without provenance | Details for goodtables-pandas-py-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| goodtables_pandas_py-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for goodtables_pandas_py-0.2.0-py3-none-any.whl |
Total release size: 33.3 kB
Release files / goodtables-pandas-py-0.2.0.tar.gz
| Download URL | goodtables-pandas-py-0.2.0.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
194171af746bf96bb2198866b31aa76cd5b4547a77f6dd55d821ad97ef268406
|
|
BLAKE2b-256 checksum How to use checksums |
f1983ce8b66fe03b6e4c57c8d63768588f30dde3615eefb6bcf231e8e777b6a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/3.8.5 Darwin/18.7.0
|
Release files / goodtables_pandas_py-0.2.0-py3-none-any.whl
| Download URL | goodtables_pandas_py-0.2.0-py3-none-any.whl |
|---|---|
| Size | 16.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85a7b9c0574f83928dff8b2a79dac12e395f17a783872dc8883792c7d634c060
|
|
BLAKE2b-256 checksum How to use checksums |
f16cece7f50e18cd73ebe2701cf2462218de8b532253620eda254c9a53f6f60f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/3.8.5 Darwin/18.7.0
|
Security for goodtables-pandas-py 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.