Skip to content

Commit b475ec6

Browse files
committed
ENH: Added Error Handling for invalid Origin
1 parent 759d5a7 commit b475ec6

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

pandas/tseries/tests/test_timeseries.py

-19
Original file line numberDiff line numberDiff line change
@@ -810,29 +810,10 @@ def test_to_datetime_origin(self):
810810

811811
# check for invalid origins
812812
for origin in invalid_origins:
813-
814-
# errors = 'raise'
815813
with self.assertRaises(ValueError):
816814
pd.to_datetime(units_from_epoch, unit=unit,
817815
origin=origin)
818816

819-
for unit in units:
820-
# errors = 'coerce'
821-
result = Series(pd.to_datetime(units_from_epoch,
822-
unit=unit,
823-
origin=origin,
824-
errors='coerce'))
825-
expected = Series([tslib.NaT, tslib.NaT, tslib.NaT,
826-
tslib.NaT, tslib.NaT])
827-
assert_series_equal(result, expected)
828-
829-
# errors = 'ignore'
830-
result = Series(pd.to_datetime(units_from_epoch,
831-
unit=unit, origin=origin,
832-
errors='ignore'))
833-
expected = Series(units_from_epoch)
834-
assert_series_equal(result, expected)
835-
836817
def test_series_ctor_datetime64(self):
837818
rng = date_range('1/1/2000 00:00:00', '1/1/2000 1:59:50', freq='10s')
838819
dates = np.asarray(rng)

pandas/tseries/tools.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
307307
1 loop, best of 3: 471 ms per loop
308308
309309
Using non-epoch origins to parse date
310-
310+
311311
>>> pd.to_datetime([1,2,3], unit='D', origin=Timestamp('1960-01-01'))
312312
0 1960-01-01
313313
1 1960-01-02
@@ -455,12 +455,7 @@ def result_without_offset(arg):
455455
try:
456456
offset = tslib.Timestamp(origin) - tslib.Timestamp(0)
457457
except ValueError:
458-
if errors == 'raise':
459-
raise ValueError("Invalid Origin or Origin Out of Bound")
460-
elif errors == 'coerce':
461-
offset = tslib.NaT
462-
elif errors == 'ignore':
463-
return arg
458+
raise ValueError("Invalid Origin or Origin Out of Bound")
464459

465460
if offset is not None:
466461
result = result + offset

0 commit comments

Comments
 (0)