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

Unexpected field-error for a boolean "example" with "trueValues" or "falseValues" properties #1610

Closed
amelie-rondot opened this issue Nov 28, 2023 · 1 comment · Fixed by #1615

Comments

@amelie-rondot
Copy link
Contributor

Overview

Using frictionless validate I got this unvalid report of validation:

frictionless validate data.csv --schema schema.json
──────────────────────────────────────────────────────────────────────────────────────────────────────────── Dataset ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
               dataset               
┏━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━┓
┃ name ┃ type  ┃ path     ┃ status  ┃
┡━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━┩
│ data │ table │ data.csv │ INVALID │
└──────┴───────┴──────────┴─────────┘
───────────────────────────────────────────────────────────────────────────────────────────────────────────── Tables ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
                                                 data                                                  
┏━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Row  ┃ Field ┃ Type        ┃ Message                                                                ┃
┡━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ None │ None  │ field-error │ Field is not valid: example value "no" for field "IsTrue" is not valid │
└──────┴───────┴─────────────┴────────────────────────────────────────────────────────────────────────┘

The error is related to the value given in the example property of the field 'IsTrue' of type boolean in the schema used for the validation, which is not valid.

I was expected a valid report of validation: I was not expected an field-error on this value example which matches with the falseValues property value, as mentionned in the boolean type of TableSchema documentation.

Resources used to reproduce the problem

  • schema.json:
    {
      "$schema": "https://frictionlessdata.io/schemas/table-schema.json",
      "fields": [
        {
          "name": "IsTrue",
          "type": "boolean",
          "trueValues": ["yes"],
          "falseValues": ["no"],
          "example": "no"
        }]
    }
    
    
  • data.csv:
    IsTrue
    no
    yes
    

Note

Replacing in the schema field 'IsTrue' the optionnal property example with 'false' instead of 'no' solves the problem. The validation report is now valid with this new schema:

  • schema.json:
    {
      "$schema": "https://frictionlessdata.io/schemas/table-schema.json",
      "fields": [
        {
          "name": "IsTrue",
          "type": "boolean",
          "trueValues": ["yes"],
          "falseValues": ["no"],
          "example": "false"
        }]
    }
    
  • data.csv:
    IsTrue
    no
    yes
    
frictionless validate data.csv --schema schema.json
──────────────────────────────────────────────────────────────────────────────────────────────────────────── Dataset ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
              dataset               
┏━━━━━━┳━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┓
┃ name ┃ type  ┃ path     ┃ status ┃
┡━━━━━━╇━━━━━━━╇━━━━━━━━━━╇━━━━━━━━┩
│ data │ table │ data.csv │ VALID  │
└──────┴───────┴──────────┴────────┘

As specified in the TableSchema boolean type documentation :
"The boolean field can be customised with these additional properties:
trueValues: [ "true", "True", "TRUE", "1" ] falseValues: [ "false", "False", "FALSE", "0" ]
format: no options (other than the default)."

But, in this case the falseValues property seems to not be applied on the example property by frictionless and retruns an unexpected field-error in the validation report.

@amelie-rondot
Copy link
Contributor Author

For more context, frictionless validate is used in Validata.fr project. We want to upgrade frictionless-py to v5 in this project. But if we do that now, the field-error exposed in this issue will block many schemas used in this project.

pierrecamilleri added a commit that referenced this issue Aug 30, 2024
…ample of a schema's boolean field using frictionless validate (#1615)

- fixes #1610

This PR fixes the `field-error` which occured doing `frictionless
validate data.csv --schema schema.json` with a `TableSchema` `schema`
containing a `BooleanField` customised with 'trueValues' or
'falseValues' and 'example' value , for example:
```
schema.json
----
{
  "$schema": "https://frictionlessdata.io/schemas/table-schema.json",
  "fields": [
    {
      "name": "IsTrue",
      "type": "boolean",
      "trueValues": ["yes"],
      "falseValues": ["no"],
      "example": "yes"
    }
  ]
}
```
```
data.csv
----
isTrue
yes
no
```

This PR add tests cases to ensure that example value is correctly
evaluated according to customized 'trueValues' or 'falseValues', as
expected.

---------

Co-authored-by: Pierre Camilleri <22995923+pierrecamilleri@users.noreply.github.com>
@pierrecamilleri pierrecamilleri changed the title Schema boolean field: Unexpected field-error related to a well-formatted value example of a schema's boolean field using frictionless validate Unexpected field-error for a boolean "example" with "trueValues" or "falseValues" properties Aug 30, 2024
pierrecamilleri added a commit that referenced this issue Sep 2, 2024
- fix: deprecated dependencies ([PR
1674](#1674))
- fix: unexpected "missing-label" error with option `header_case =
False`
([#1635](#1635))
- fix: KeyError when a "primaryKey" is missing
([#1633](#1633))
- fix: unexpected field-error for a boolean "example" with "trueValues"
or
"falseValues" properties
([#1610](#1610))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant