Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Questions about representation of numbers

See original GitHub issue

Issue Description

Dear devs, Example schema: number1:int() number2:float()

1.Why 1e4 or 1.1e4 are not recognized as valid int. Should be possible imho. 2. Why build in float validator brings error on numbers without decimal point. I.e. 10.0 is valid but 10 is not valid double. Seems illogical, since ppl never add “.” to such numbers

I have created own validator, which did the job. But may be support is natively? Thanks you very much for great tool!

`#custom type int64 class int64_type_validator(Validator): “”" Custom Int64 validator “”" tag = ‘int64’
def _is_valid(self, value): strg=str(value) try: f=float(value) i=np.int64(f) return (f-i)==0 #Notes: # TBD:May be add epsilon? # Is 10.1e9 valid input of int64. So far yes. or do we want to limit AeB except: return False

class float_type_validator(Validator): “”" Custom float validator “”" tag = ‘float’

def _is_valid(self, value):
        return True          
        return False`

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10

github_iconTop GitHub Comments

mildebrandtcommented, Dec 8, 2021

Yamale leaves the parsing up to the Python library being used. Yamale validates the values based on the Python types which the parser assigned. I don’t see it as a weakness of either the parser (ruamel) or the validator (yamale). Both try to be explicit in what they do. The ruamel parser assigns 1e4 to a float, and yamale correctly says a float is not an integer. For example, I’d also expect 1.0 to fail a validation if an integer was required since 1.0 is a float.

I can see why someone would think the other way. You’re saying that if I can cast/convert a float to an integer successfully, then yamale should validate as an integer. I could also cast 1.0 as a string…but one would expect the validator to fail if the user provided 1.0 and the schema expected a string instead. For that reason, yamale validates against the actual types that the parser gives it instead of what it can be cast/converted into.

mildebrandtcommented, Dec 7, 2021

Both make_data() and make_schema() have a parser parameter that you can set. There’s an example in the README here:

# Import Yamale and make a schema object, make sure ruamel.yaml is installed already.
import yamale
schema = yamale.make_schema('./schema.yaml', parser='ruamel')

# Create a Data object
data = yamale.make_data('./data.yaml', parser='ruamel')

# Validate data against the schema same as before.
yamale.validate(schema, data)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Number Representation - GeeksforGeeks
Number Representation · Question 1. The smallest integer that can be represented by an 8-bit number in 2's complement form is · Question...
Read more >
Numbers Representation Questions and Answers - Sanfoundry
This set of Mathematics Multiple Choice Questions & Answers (MCQs) focuses on “Representation of Numbers on Number Line”. 1. On a number line, ......
Read more >
Problems on Representation of Rational Numbers on Number ...
Problems on Representation of Rational Numbers on Number Line · 1. Represent 45on the number line. Solution: · 2. Represent 73 on the...
Read more >
W1(Lect 1):1.2 Number System & Representation - Quizizz
Which way of representing numbers? answer choices. Numerical representation. Numbering system. Number presentation. none of these. 5. Multiple-choice.
Read more >
Number Representation MCQ [Free PDF] - Objective Question ...
Number Representation Question 1: · The decimal value of n1 is 3.5 · The decimal value of n1 is 4.5 · The decimal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found