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

Add support for decimal logical type #86

Merged
merged 10 commits into from
Nov 24, 2020

Conversation

xgamer4
Copy link
Contributor

@xgamer4 xgamer4 commented Nov 17, 2020

Added in functionality for Decimal logical data types based of Python's decimal.Decimal class, added in fields and types.
Added in types and fields definitions for Decimal. Added in tests for fields and updated documentation. decimal.Decimal types can be declared in two ways:

class Example(AvroModel):
   implicit: decimal.Decimal = decimal.Decimal('3.14')  # scale = 2, precision = 3, inherit from default
   explicit: decimal.Decimal = types.Decimal(scale=2, precision=3, [default=decimal.Decimal('3.14'])

@xgamer4 xgamer4 marked this pull request as ready for review November 18, 2020 21:27
@xgamer4
Copy link
Contributor Author

xgamer4 commented Nov 18, 2020

Little bit of reorganization of the added functions, added in serialization and schema tests, added in documentation, linted and tested.

Off the discussion in Issue 84, this was tweaked to error out on a decimal.Decimal field with no default. The docs also make it clear that defining scale and precision explicitly with types.Decimal is preferable to decimal.Decimal

dataclasses_avroschema/fields.py:816: error: Incompatible types in assignment (expression has type "type", variable has type "Type[InmutableField]")
dataclasses_avroschema/fields.py:816: note: "type.__call__" has type "Callable[[VarArg(Any), KwArg(Any)], Any]"

and couldn't figure out why
@xgamer4 xgamer4 changed the title IN PROGRESS Add support for decimal logical type Nov 18, 2020
@codecov-io
Copy link

codecov-io commented Nov 21, 2020

Codecov Report

Merging #86 (e07efe0) into master (0a819c4) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #86      +/-   ##
==========================================
+ Coverage   99.50%   99.55%   +0.04%     
==========================================
  Files           7        7              
  Lines         608      672      +64     
  Branches       93      105      +12     
==========================================
+ Hits          605      669      +64     
  Misses          1        1              
  Partials        2        2              
Impacted Files Coverage Δ
dataclasses_avroschema/fields.py 99.50% <100.00%> (+0.04%) ⬆️
dataclasses_avroschema/serialization.py 100.00% <100.00%> (ø)
dataclasses_avroschema/types.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 0a819c4...9e9d360. Read the comment docs.

dataclasses_avroschema/serialization.py Outdated Show resolved Hide resolved
dataclasses_avroschema/fields.py Outdated Show resolved Hide resolved
dataclasses_avroschema/fields.py Outdated Show resolved Hide resolved
@marcosschroh
Copy link
Owner

Looking good @xgamer4 . Just minors comments

@marcosschroh marcosschroh merged commit 6f5068f into marcosschroh:master Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants