aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrock Mendel <jbrockmendel@gmail.com>2017-12-13 09:08:28 -0800
committerPaul Ganssle <paul@ganssle.io>2018-03-11 18:15:59 -0400
commit87961706661f4fb95a5057ebb0ccf8ebad3f5efc (patch)
treea8a519a5396ca7a61c600d8a5a70b40541042fe3
parent1dfa77a2e87dcfd1cf277c69c27dea0ec8530f77 (diff)
downloaddateutil-87961706661f4fb95a5057ebb0ccf8ebad3f5efc.tar.gz
warn instead of raising... for now
edit warning per suggestion
-rw-r--r--dateutil/parser/_parser.py24
-rw-r--r--dateutil/test/test_parser.py11
2 files changed, 20 insertions, 15 deletions
diff --git a/dateutil/parser/_parser.py b/dateutil/parser/_parser.py
index a5ec2fb..de81fdc 100644
--- a/dateutil/parser/_parser.py
+++ b/dateutil/parser/_parser.py
@@ -34,6 +34,7 @@ import datetime
import re
import string
import time
+import warnings
from calendar import monthrange
from io import StringIO
@@ -613,14 +614,6 @@ class parser(object):
if not ignoretz:
ret = self._build_tzaware(ret, res, tzinfos)
- elif not res.tzname and not res.tzoffset:
- # i.e. no timezone information was found.
- pass
- else:
- # tz-like string was parsed but we don't know what to do
- # with it
- raise ValueError(res.tzname)
-
if kwargs.get('fuzzy_with_tokens', False):
return ret, skipped_tokens
else:
@@ -1153,9 +1146,18 @@ class parser(object):
elif res.tzoffset:
aware = naive.replace(tzinfo=tz.tzoffset(res.tzname, res.tzoffset))
- else:
- # TODO: this is really only the right thing to do if no tz
- # information was found.
+ elif not res.tzname and not res.tzoffset:
+ # i.e. no timezone information was found.
+ aware = naive
+
+ elif res.tzname:
+ # tz-like string was parsed but we don't know what to do
+ # with it
+ warnings.warn("tzname {tzname} identified but not understood. "
+ "Pass `tzinfos` argument in order to correctly "
+ "return a timezone-aware datetime. In a future "
+ "version, this raise an "
+ "exception.".format(tzname=res.tzname))
aware = naive
return aware
diff --git a/dateutil/test/test_parser.py b/dateutil/test/test_parser.py
index ce27e82..961ae3d 100644
--- a/dateutil/test/test_parser.py
+++ b/dateutil/test/test_parser.py
@@ -574,8 +574,9 @@ class ParserTest(unittest.TestCase):
def testFuzzyIgnoreAMPM(self):
s1 = "Jan 29, 1945 14:45 AM I going to see you there?"
-
- self.assertEqual(parse(s1, fuzzy=True), datetime(1945, 1, 29, 14, 45))
+ with pytest.warns(UserWarning, match="identified but not understood"):
+ res = parse(s1, fuzzy=True)
+ self.assertEqual(res, datetime(1945, 1, 29, 14, 45))
def testExtraSpace(self):
self.assertEqual(parse(" July 4 , 1976 12:01:02 am "),
@@ -683,8 +684,10 @@ class ParserTest(unittest.TestCase):
datetime(2003, 9, 25, 12, 8))
def testRandomFormat26(self):
- self.assertEqual(parse("5:50 A.M. on June 13, 1990"),
- datetime(1990, 6, 13, 5, 50))
+ with pytest.warns(UserWarning, match="identified but not understood"):
+ res = parse("5:50 A.M. on June 13, 1990")
+
+ self.assertEqual(res, datetime(1990, 6, 13, 5, 50))
def testRandomFormat27(self):
self.assertEqual(parse("3rd of May 2001"), datetime(2001, 5, 3))