Add FractionField
Open
Nobody has claimed this yet.
rows.fields
- Dominant language
- Python
- Stars
- 886
- Forks
- 137
- PR merge metrics
- No merged PRs in 30d
Description
Sometimes it's useful to represent fractions, instead of using float or decimal.Decimal. Python has the fractions module in the stdlib (both Python 2 and 3) and we could use it.
A draft implementation (needs to check some corner cases, add tests):
from fractions import Fraction
class FractionField(rows.fields.Field):
TYPE = (Fraction, )
@classmethod
def deserialize(cls, value):
value = str(value or '').strip()
if not value:
return None
try:
return Fraction(value)
except ValueError:
raise
@classmethod
def serialize(cls, value):
if value is None:
return ''
else:
return str(value)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing rows.fields.Field implementation and the field tests, then compare their conventions with Python's fractions module and the draft FractionField shown here. Add coverage for normal values and corner cases, with completion shown by passing the field tests and correct Fraction serialization and deserialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100