From 59626a2fc922baba8c95d4c38d34dd80531669c4 Mon Sep 17 00:00:00 2001 From: Christopher Groskopf Date: Fri, 22 Jan 2016 22:53:45 -0600 Subject: [PATCH] Use repr instead of string formatting to convert floats. Closes #428. --- CHANGELOG.rst | 1 + agate/data_types/number.py | 10 ++-------- agate/table.py | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4aaee219a..1d38fe116 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) diff --git a/agate/data_types/number.py b/agate/data_types/number.py index f1f98d532..e237a57ca 100644 --- a/agate/data_types/number.py +++ b/agate/data_types/number.py @@ -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): """ @@ -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('%') diff --git a/agate/table.py b/agate/table.py index 2ce29c249..e2598df80 100644 --- a/agate/table.py +++ b/agate/table.py @@ -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) @@ -1000,7 +1000,7 @@ def aggregate(self, aggregations): return tuple(results) else: aggregations.validate(self) - + return aggregations.run(self) @allow_tableset_proxy