Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #72 from sernst/decimal-type-rendering
Browse files Browse the repository at this point in the history
Decimal Type Rendering
  • Loading branch information
sernst committed Sep 11, 2020
2 parents c5feed9 + d8d7d33 commit 4bb36d6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cauldron/render/encoding.py
Expand Up @@ -2,6 +2,7 @@
import json
import numpy as np
import pandas as pd
import decimal
import typing
from collections import namedtuple

Expand All @@ -14,6 +15,8 @@
def default_override(value: typing.Any):
"""..."""

if isinstance(value, decimal.Decimal):
return float(value)
if isinstance(value, datetime.date):
return value.isoformat()
elif isinstance(value, datetime.datetime):
Expand Down
2 changes: 1 addition & 1 deletion cauldron/settings.json
@@ -1,4 +1,4 @@
{
"version": "1.0.3",
"version": "1.0.4",
"notebookVersion": "v1"
}
12 changes: 7 additions & 5 deletions cauldron/test/render/test_render.py
Expand Up @@ -2,6 +2,7 @@
import os
from unittest.mock import patch
from datetime import date
import decimal

import pandas as pd
from cauldron import render
Expand All @@ -13,12 +14,13 @@ class TestRender(scaffolds.ResultsTest):

def test_table(self):
"""Should render a table"""

dt = date(2016, 9, 9)
d = decimal.Decimal('3.14')
df = pd.DataFrame([
{'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
{'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
{'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)},
{'a': 1, 'b': 'hello', 'c': True, 'd': date(2016, 9, 9)}
{'a': 1, 'b': 'hello', 'c': True, 'd': dt, 'e': d},
{'a': 1, 'b': 'hello', 'c': True, 'd': dt, 'e': d},
{'a': 1, 'b': 'hello', 'c': True, 'd': dt, 'e': d},
{'a': 1, 'b': 'hello', 'c': True, 'd': dt, 'e': d}
])

result = render.table(df, 0.5, include_index=True)
Expand Down
2 changes: 1 addition & 1 deletion cauldron/test/support/mocking.py
Expand Up @@ -65,4 +65,4 @@ def __enter__(self):
return self.mock_importer

def __exit__(self, *args, **kwargs):
return self._patch.__exit__()
return self._patch.__exit__(*args)
5 changes: 5 additions & 0 deletions development.dockerfile
@@ -0,0 +1,5 @@
FROM python:3.8

COPY requirements.txt /build-data/requirements.txt

RUN pip install -r /build-data/requirements.txt --upgrade

0 comments on commit 4bb36d6

Please sign in to comment.