Skip to content

Defining optional fields to resources or a way to ignore additional fields in data? #678

Answered by roll
pchtsp asked this question in Q&A
Discussion options

You must be logged in to vote

@pchtsp
Your idea was very smart and only the bug was preventing it from working. With [email protected]:

from pprint import pprint
from frictionless import Package, Resource, Schema, Field, Detector, validate

package = Package(
    resources=[
        Resource(
            data=[["f1"], ["v1"], ["v2"], ["v3"]],
            schema=Schema(fields=[Field(name="f1"), Field(name="f2")]),
        ),
    ]
)

pprint(validate(package).valid)  # False


def validate_with_optinal_fields(package):
    for resource in package.resources:
        resource.detector = Detector(schema_sync=True)
    return validate(package)


pprint(validate_with_optinal_fields(package).valid)  # True

The function, of …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
4 replies
@roll
Comment options

roll May 10, 2021
Maintainer

@pchtsp
Comment options

@pchtsp
Comment options

@roll
Comment options

roll May 12, 2021
Maintainer

Comment options

You must be logged in to vote
0 replies
Answer selected by roll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants