Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility of restricting the list of possible values ​​in an "array" type field #627

Closed
roll opened this issue Jan 25, 2021 · 7 comments · Fixed by #750
Closed

Possibility of restricting the list of possible values ​​in an "array" type field #627

roll opened this issue Jan 25, 2021 · 7 comments · Fixed by #750
Labels
feature New functionality

Comments

@roll
Copy link
Member

roll commented Jan 25, 2021

Overview

There is an issue for the specs that can be supported in advance in Frictionless-py as it's blocking for french open data task force Etalab (cc @lwinfree)

frictionlessdata/specs#712

@roll
Copy link
Member Author

roll commented Mar 1, 2021

Prioritizing this one to unblock Etalab cc @lwinfree

@roll
Copy link
Member Author

roll commented Mar 9, 2021

Hi @johanricher,

Could you please try with frictionless@4.1:

from pprint import pprint
from frictionless import Resource, Schema, Field

field = Field(name="key", type="array", array_item={"constraints": {"enum": ["a", "b"]}})
resource = Resource([["key"], [["a"]], [["b"]], [["c"]]], schema=Schema(fields=[field]))
pprint(resource.read_rows())

@roll
Copy link
Member Author

roll commented Mar 9, 2021

Here is details - frictionlessdata/specs#409 (comment)

@geoffreyaldebert
Copy link

geoffreyaldebert commented Mar 12, 2021

Hello @roll
First of all, thanks for your answer and proposition. Indeed, the solution works on python.

But the command line does not seems to work properly when we try to validate a file.

Example of schema :

...
   "fields":[
      {
         "name":"array_field",
         "title":"Array field",
         "description":"Array field description",
         "type":"array",
         "example":"",
         "array_item":{
            "constraints": {
               "enum": ["a", "b"]
            }
         }
      }
   ]
...

Example of csv file :

array_field
"[""a""]"
"[""a"",""b""]"
"[""a"",""b"",""c""]"
"[""c""]"

Value c is not in the enum list however when I execute frictionless validate --schema schema.json exemple-valide.csv the output message does not mention any error :
image

You have the repo for test here : https://github.com/geoffreyaldebert/schema-test

Any idea why this is working on python but not with CLI ?

Thanks for your help !

Geoffrey

cc @johanricher

@geoffreyaldebert
Copy link

@roll sorry for my latest message, I found the answer.

Property array_item was not good (it was arrayItem). With this new implementation, it works fine.

Thanks you can keep this issue closed !

cc @johanricher

@johanricher
Copy link
Member

Great news @geoffreyaldebert! Thank you so much @roll, we really appreciate it. 👍

@roll
Copy link
Member Author

roll commented Mar 14, 2021

Great! Thanks.

Please create an issue if you run into any troubles using it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants