Skip to content

Commit

Permalink
Don't strip whitespace from Text. Closes #654.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed Dec 29, 2016
1 parent 8865ddf commit 28ae01b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
1.5.5
-----

* Fixed :code:`'NoneType' object has no attribute 'groupdict'` in :meth:`.TimeDelta.cast`. (#656)
* :meth:`.Text.cast` will no longer strip leading or trailing whitespace. (#654)
* Fixed :code:`'NoneType' object has no attribute 'groupdict'` error in :meth:`.TimeDelta.cast`. (#656)

1.5.4 - December 27, 2016
-------------------------
Expand Down
4 changes: 1 addition & 3 deletions agate/data_types/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def cast(self, d):
if d is None:
return d
elif isinstance(d, six.string_types):
d = d.strip()

if self.cast_nulls and d.lower() in self.null_values:
if self.cast_nulls and d.strip().lower() in self.null_values:
return None

return six.text_type(d)
4 changes: 2 additions & 2 deletions tests/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def test_test(self):
self.assertEqual(self.type.test(u'👍'), True)

def test_cast(self):
values = ('a', 1, None, Decimal('2.7'), 'n/a', u'👍')
values = ('a', 1, None, Decimal('2.7'), 'n/a', u'👍', ' foo', 'foo ')
casted = tuple(self.type.cast(v) for v in values)
self.assertSequenceEqual(casted, ('a', '1', None, '2.7', None, u'👍'))
self.assertSequenceEqual(casted, ('a', '1', None, '2.7', None, u'👍', ' foo', 'foo '))

def test_no_cast_nulls(self):
values = ('', 'N/A', None)
Expand Down

0 comments on commit 28ae01b

Please sign in to comment.