From 0db07b50547394e386ed54e263a29be147fcea43 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Wed, 19 Oct 2016 11:12:46 -0400 Subject: [PATCH 1/7] updated docstring in .to_datetime() --- pandas/tseries/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index 93d35ff964e69..b48960a901dd0 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -270,7 +270,7 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, If a date that does not meet timestamp limitations, passing errors='coerce' will force to NaT. Furthermore this will force non-dates to NaT as well. - >>> pd.to_datetime('13000101', format='%Y%m%d') + >>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore') datetime.datetime(1300, 1, 1, 0, 0) >>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce') NaT From c16ad6b9164b5893f4e67ab4d070fed5ef2f2295 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 23 Oct 2016 00:29:18 -0400 Subject: [PATCH 2/7] added timestamp limitations and default behavior to docstring --- pandas/tseries/tools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index b48960a901dd0..0c1ad6ea6d08d 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -267,11 +267,13 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, 1 2016-03-05 dtype: datetime64[ns] - If a date that does not meet timestamp limitations, passing errors='coerce' - will force to NaT. Furthermore this will force non-dates to NaT as well. - + Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years. + + If a date that does not meet timestamp limitations, passing errors='ignore' will simply return the original input instead of raising any exception. >>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore') datetime.datetime(1300, 1, 1, 0, 0) + + Passing errors='coerce' will force to NaT. Furthermore this will force non-dates to NaT as well. >>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce') NaT From 7402de4d5797d6fc72ea577b4bc785de128e4c29 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 23 Oct 2016 12:32:08 -0400 Subject: [PATCH 3/7] edited docstring to fit python standards --- pandas/tseries/tools.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index 0c1ad6ea6d08d..c56dc93a2e743 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -30,6 +30,7 @@ def _lexer_split_from_str(dt_str): # The StringIO(str(_)) is for dateutil 2.2 compatibility return _timelex.split(compat.StringIO(str(dt_str))) + _DATEUTIL_LEXER_SPLIT = _lexer_split_from_str except (ImportError, AttributeError): pass @@ -43,6 +44,7 @@ def _infer(a, b): raise AssertionError('Inputs must both have the same timezone,' ' {0} != {1}'.format(tz, b.tzinfo)) return tz + tz = None if start is not None: tz = _infer(start, end) @@ -133,7 +135,7 @@ def _guess_datetime_format(dt_str, dayfirst=False, for i, token_format in enumerate(format_guess): token_filled = tokens[i].zfill(padding) if (token_format is None and - token_filled == parsed_datetime.strftime(attr_format)): + token_filled == parsed_datetime.strftime(attr_format)): format_guess[i] = attr_format tokens[i] = token_filled found_attrs.update(attrs) @@ -267,13 +269,14 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, 1 2016-03-05 dtype: datetime64[ns] - Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years. - - If a date that does not meet timestamp limitations, passing errors='ignore' will simply return the original input instead of raising any exception. + Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit + integer is limited to approximately 584 years. + If a date that does not meet timestamp limitations, passing errors='ignore' will simply return the original input + instead of raising any exception. + Passing errors='coerce' will force to NaT. Furthermore this will force non-dates to NaT as well. + >>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore') datetime.datetime(1300, 1, 1, 0, 0) - - Passing errors='coerce' will force to NaT. Furthermore this will force non-dates to NaT as well. >>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce') NaT @@ -425,6 +428,7 @@ def _convert_listlike(arg, box, format, name=None, tz=tz): return _convert_listlike(np.array([arg]), box, format)[0] + # mappings for assembling units _unit_map = {'year': 'year', 'years': 'year', @@ -557,7 +561,7 @@ def calc_with_mask(carg, mask): result = np.empty(carg.shape, dtype='M8[ns]') iresult = result.view('i8') iresult[~mask] = tslib.iNaT - result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)).\ + result[mask] = calc(carg[mask].astype(np.float64).astype(np.int64)). \ astype('M8[ns]') return result @@ -642,7 +646,6 @@ def parse_time_string(arg, freq=None, dayfirst=None, yearfirst=None): DateParseError = tslib.DateParseError normalize_date = tslib.normalize_date - # Fixed time formats for time parsing _time_formats = ["%H:%M", "%H%M", "%I:%M%p", "%I%M%p", "%H:%M:%S", "%H%M%S", "%I:%M:%S%p", "%I%M%S%p"] @@ -768,6 +771,7 @@ def format(dt): """Returns date in YYYYMMDD format.""" return dt.strftime('%Y%m%d') + OLE_TIME_ZERO = datetime(1899, 12, 30, 0, 0, 0) From 5ed8ef5c1f5baa30d4782982578a4db535f456ed Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 23 Oct 2016 13:20:10 -0400 Subject: [PATCH 4/7] edut docstring to fit Python Standards --- pandas/tseries/tools.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index c56dc93a2e743..a662cefb30b33 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -30,12 +30,10 @@ def _lexer_split_from_str(dt_str): # The StringIO(str(_)) is for dateutil 2.2 compatibility return _timelex.split(compat.StringIO(str(dt_str))) - _DATEUTIL_LEXER_SPLIT = _lexer_split_from_str except (ImportError, AttributeError): pass - def _infer_tzinfo(start, end): def _infer(a, b): tz = a.tzinfo @@ -52,7 +50,6 @@ def _infer(a, b): tz = _infer(end, start) return tz - def _guess_datetime_format(dt_str, dayfirst=False, dt_str_parse=compat.parse_date, dt_str_split=_DATEUTIL_LEXER_SPLIT): @@ -269,11 +266,13 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, 1 2016-03-05 dtype: datetime64[ns] - Since pandas represents timestamps in nanosecond resolution, the timespan that can be represented using a 64-bit - integer is limited to approximately 584 years. - If a date that does not meet timestamp limitations, passing errors='ignore' will simply return the original input - instead of raising any exception. - Passing errors='coerce' will force to NaT. Furthermore this will force non-dates to NaT as well. + Since pandas represents timestamps in nanosecond resolution, the timespan + that can be represented using a 64-bit integer is limited to approximately + 584 years. + If a date that does not meet timestamp limitations, passing errors='ignore' + will simply return the original input instead of raising any exception. + Passing errors='coerce' will force to NaT. Furthermore this will force + non-dates to NaT as well. >>> pd.to_datetime('13000101', format='%Y%m%d', errors='ignore') datetime.datetime(1300, 1, 1, 0, 0) From 8bfa58ee19edb3839651ddb4adb58c7a9fb85dc9 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 23 Oct 2016 14:08:15 -0400 Subject: [PATCH 5/7] edited docstring to fit python standards --- pandas/tseries/tools.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index a662cefb30b33..142e7c7b899c8 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -34,6 +34,7 @@ def _lexer_split_from_str(dt_str): except (ImportError, AttributeError): pass + def _infer_tzinfo(start, end): def _infer(a, b): tz = a.tzinfo @@ -50,6 +51,7 @@ def _infer(a, b): tz = _infer(end, start) return tz + def _guess_datetime_format(dt_str, dayfirst=False, dt_str_parse=compat.parse_date, dt_str_split=_DATEUTIL_LEXER_SPLIT): From 3aa78cf021ab0ca3680a0d42a9796c6e4a86b425 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Sun, 23 Oct 2016 15:46:23 -0400 Subject: [PATCH 6/7] edit docstring to fit python standards --- pandas/tseries/tools.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index 142e7c7b899c8..a8e1b5a9cca6a 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -34,7 +34,7 @@ def _lexer_split_from_str(dt_str): except (ImportError, AttributeError): pass - + def _infer_tzinfo(start, end): def _infer(a, b): tz = a.tzinfo @@ -51,7 +51,7 @@ def _infer(a, b): tz = _infer(end, start) return tz - + def _guess_datetime_format(dt_str, dayfirst=False, dt_str_parse=compat.parse_date, dt_str_split=_DATEUTIL_LEXER_SPLIT): @@ -134,7 +134,7 @@ def _guess_datetime_format(dt_str, dayfirst=False, for i, token_format in enumerate(format_guess): token_filled = tokens[i].zfill(padding) if (token_format is None and - token_filled == parsed_datetime.strftime(attr_format)): + token_filled == parsed_datetime.strftime(attr_format)): format_guess[i] = attr_format tokens[i] = token_filled found_attrs.update(attrs) From 5468fc53fe2035e436d073eff02be76b63322c35 Mon Sep 17 00:00:00 2001 From: Keshav Ramaswamy Date: Mon, 24 Oct 2016 18:23:03 -0400 Subject: [PATCH 7/7] added link to timestamp limitations in docstring --- pandas/tseries/tools.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandas/tseries/tools.py b/pandas/tseries/tools.py index a8e1b5a9cca6a..68182b6f7267e 100644 --- a/pandas/tseries/tools.py +++ b/pandas/tseries/tools.py @@ -267,11 +267,10 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False, 0 2015-02-04 1 2016-03-05 dtype: datetime64[ns] - - Since pandas represents timestamps in nanosecond resolution, the timespan - that can be represented using a 64-bit integer is limited to approximately - 584 years. - If a date that does not meet timestamp limitations, passing errors='ignore' + + If a date that does not meet `timestamp limitations + `_, passing errors='ignore' will simply return the original input instead of raising any exception. Passing errors='coerce' will force to NaT. Furthermore this will force non-dates to NaT as well.