cldf / csvw

CSV on the web
Apache License 2.0
36 stars 5 forks source link

added nonNegativeInteger #35

Closed stschiff closed 4 years ago

stschiff commented 4 years ago

just added this one new datatype, perhaps more to come if need be.

xrotwang commented 4 years ago

@stschiff do you want to take a stab at adding tests as well, or should I do?

stschiff commented 4 years ago

Ah right. Of course. Will do! And I will leave that topic branch open for now anyway, perhaps there'll be more types.

stschiff commented 4 years ago

OK, I've fixed the test, but it's not clear to me whether it's correct what I'm doing here. I'm currently raising a ValueError when parsing, but you seem to be separating parsing from validating.

xrotwang commented 4 years ago

@stschiff I just remembered why I didn't implement nonNegativeInteger. csvw.metadata.Datatype already has an attribute minimum which when used together with integer will provide what you want:

{
    "name": "...",
    "datatype": {
        "base": "integer",
        "minimum": 0
    }
}
codecov-io commented 4 years ago

Codecov Report

Merging #35 into master will increase coverage by 0.00%. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #35   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files          15       15           
  Lines        2211     2222   +11     
=======================================
+ Hits         2209     2220   +11     
  Misses          2        2           
Impacted Files Coverage Δ
src/csvw/datatypes.py 100.00% <100.00%> (ø)
tests/test_datatypes.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f943480...8775561. Read the comment docs.

stschiff commented 4 years ago

@stschiff I just remembered why I didn't implement nonNegativeInteger. csvw.metadata.Datatype already has an attribute minimum which when used together with integer will provide what you want.

Yes, that makes sense, I also realised as much. I'm open to doing it this way, it would require some minor changes in my schemas, but nothing dramatic. Up to you. The official csvw standard has all these edge-case datatypes, in principle, so perhaps it's good to support them even if they're somewhat redundant.

xrotwang commented 4 years ago

Yes, I think we should support as many as possible, in particular if its not much work (o the work is already done :) ).

xrotwang commented 4 years ago

I'm not a big fan of topic branches, though, or any other kind of long-lived branch - so I'll merge now :)