Skip to content

Commit

Permalink
Use repr instead of string formatting to convert floats. Closes wires…
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Jan 23, 2016
1 parent a285332 commit 59626a2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
1.2.1
-----

* Removed ``float_precision`` argument from :class:`.Number`. (#428)
* :class:`.AgateTestCase` is now available as ``agate.AgateTestCase``. (#426)
* :meth:`.TableSet.to_json` now has an ``indent`` option for use with ``nested``.
* :meth:`.TableSet.to_json` now has a ``nested`` option for writing a single, nested JSON file. (#417)
Expand Down
10 changes: 2 additions & 8 deletions agate/data_types/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,11 @@ class Number(DataType):
:param locale:
A locale specification such as :code:`en_US` or :code:`de_DE` to use
for parsing formatted numbers.
:param float_precision:
An integer specifying how many decimal places to include when
converting Python's native floats to Decimals. Beyond this point values
will be rounded. This does *not* apply to string representations of
fractional numbers.
"""
def __init__(self, locale='en_US', float_precision=10, **kwargs):
def __init__(self, locale='en_US', **kwargs):
super(Number, self).__init__(**kwargs)

self.locale = locale
self.float_format = '%%.%if' % float_precision

def cast(self, d):
"""
Expand All @@ -46,7 +40,7 @@ def cast(self, d):
elif type(d) is int:
return Decimal(d)
elif type(d) is float:
return Decimal(self.float_format % d)
return Decimal(repr(d))
elif isinstance(d, six.string_types):
d = d.strip()
d = d.strip('%')
Expand Down
6 changes: 3 additions & 3 deletions agate/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ def rename(self, column_names=None, row_names=None):

if isinstance(row_names, dict):
row_names = [row_names[name] if name in row_names else name for name in self.row_names]

if column_names is not None and column_names != self.column_names:
if row_names is None:
row_names = self._row_names

return Table(self.rows, column_names, self.column_types, row_names=row_names, _is_fork=False)
else:
return self._fork(self.rows, column_names, self._column_types, row_names=row_names)
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def aggregate(self, aggregations):
return tuple(results)
else:
aggregations.validate(self)

return aggregations.run(self)

@allow_tableset_proxy
Expand Down

0 comments on commit 59626a2

Please sign in to comment.