def test_guess_datetime_format_with_locale_specific_formats( self, string, format): # The month names will vary depending on the locale, in which # case these wont be parsed properly (dateutil can't parse them) tm._skip_if_has_locale() result = parsing._guess_datetime_format(string) assert result == format
def test_guess_datetime_format_with_locale_specific_formats(self): # The month names will vary depending on the locale, in which # case these wont be parsed properly (dateutil can't parse them) tm._skip_if_has_locale() dt_string_to_format = (('30/Dec/2011', '%d/%b/%Y'), ('30/December/2011', '%d/%B/%Y'), ('30/Dec/2011 00:00:00', '%d/%b/%Y %H:%M:%S'), ) for dt_string, dt_format in dt_string_to_format: assert parsing._guess_datetime_format(dt_string) == dt_format
def test_guess_datetime_format_nopadding(self): # GH 11142 dt_string_to_format = (('2011-1-1', '%Y-%m-%d'), ('30-1-2011', '%d-%m-%Y'), ('1/1/2011', '%m/%d/%Y'), ('2011-1-1 00:00:00', '%Y-%m-%d %H:%M:%S'), ('2011-1-1 0:0:0', '%Y-%m-%d %H:%M:%S'), ('2011-1-3T00:00:0', '%Y-%m-%dT%H:%M:%S')) for dt_string, dt_format in dt_string_to_format: assert parsing._guess_datetime_format(dt_string) == dt_format
def test_guess_datetime_format_with_parseable_formats(self): tm._skip_if_not_us_locale() dt_string_to_format = (('20111230', '%Y%m%d'), ('2011-12-30', '%Y-%m-%d'), ('30-12-2011', '%d-%m-%Y'), ('2011-12-30 00:00:00', '%Y-%m-%d %H:%M:%S'), ('2011-12-30T00:00:00', '%Y-%m-%dT%H:%M:%S'), ('2011-12-30 00:00:00.000000', '%Y-%m-%d %H:%M:%S.%f'), ) for dt_string, dt_format in dt_string_to_format: assert parsing._guess_datetime_format(dt_string) == dt_format
def test_guess_datetime_format_invalid_inputs(self): # A datetime string must include a year, month and a day for it # to be guessable, in addition to being a string that looks like # a datetime invalid_dts = [ '2013', '01/2013', '12:00:00', '1/1/1/1', 'this_is_not_a_datetime', '51a', 9, datetime(2011, 1, 1), ] for invalid_dt in invalid_dts: assert parsing._guess_datetime_format(invalid_dt) is None
def test_guess_datetime_format_invalid_inputs(self): # A datetime string must include a year, month and a day for it # to be guessable, in addition to being a string that looks like # a datetime invalid_dts = [ '2013', '01/2013', '12:00:00', '1/1/1/1', 'this_is_not_a_datetime', '51a', 9, datetime(2011, 1, 1), ] for invalid_dt in invalid_dts: assert parsing._guess_datetime_format(invalid_dt) is None
def test_guess_datetime_format_with_dayfirst(dayfirst, expected): ambiguous_string = "01/01/2011" result = parsing._guess_datetime_format(ambiguous_string, dayfirst=dayfirst) assert result == expected
def test_guess_datetime_format_with_parseable_formats(string, fmt): result = parsing._guess_datetime_format(string) assert result == fmt
def test_guess_datetime_format_nopadding(self, string, format): # GH 11142 result = parsing._guess_datetime_format(string) assert result == format
def _guess_datetime_format_for_array(arr, **kwargs): # Try to guess the format based on the first non-NaN element non_nan_elements = notna(arr).nonzero()[0] if len(non_nan_elements): return _guess_datetime_format(arr[non_nan_elements[0]], **kwargs)
def test_guess_datetime_format_with_dayfirst(self): ambiguous_string = '01/01/2011' assert parsing._guess_datetime_format( ambiguous_string, dayfirst=True) == '%d/%m/%Y' assert parsing._guess_datetime_format( ambiguous_string, dayfirst=False) == '%m/%d/%Y'
def test_guess_datetime_format_with_dayfirst(dayfirst, expected): ambiguous_string = "01/01/2011" result = parsing._guess_datetime_format(ambiguous_string, dayfirst=dayfirst) assert result == expected
def test_guess_datetime_format_invalid_inputs(invalid_dt): # A datetime string must include a year, month and a day for it to be # guessable, in addition to being a string that looks like a datetime. assert parsing._guess_datetime_format(invalid_dt) is None
def test_guess_datetime_format_with_locale_specific_formats(string, fmt): result = parsing._guess_datetime_format(string) assert result == fmt
def test_guess_datetime_format_no_padding(string, fmt): # see gh-11142 result = parsing._guess_datetime_format(string) assert result == fmt
def test_guess_datetime_format_nopadding_gt_261(self, string): # GH 11142 result = parsing._guess_datetime_format(string) assert result is None
def test_guess_datetime_format_with_locale_specific_formats_gt_261( self, string): result = parsing._guess_datetime_format(string) assert result is None
def test_guess_datetime_format_with_dayfirst_gt_261(self, dayfirst): ambiguous_string = '01/01/2011' result = parsing._guess_datetime_format( ambiguous_string, dayfirst=dayfirst) assert result is None
def test_guess_datetime_format_with_parseable_formats_gt_261( self, string): result = parsing._guess_datetime_format(string) assert result is None
def test_guess_datetime_format_with_parseable_formats( self, string, format): tm._skip_if_not_us_locale() result = parsing._guess_datetime_format(string) assert result == format
def test_guess_datetime_format_invalid_inputs(invalid_dt): # A datetime string must include a year, month and a day for it to be # guessable, in addition to being a string that looks like a datetime. assert parsing._guess_datetime_format(invalid_dt) is None
def test_guess_datetime_format_nopadding(self, string, format): # GH 11142 result = parsing._guess_datetime_format(string) assert result == format
def test_guess_datetime_format_with_parseable_formats(string, fmt): result = parsing._guess_datetime_format(string) assert result == fmt
def test_guess_datetime_format_with_parseable_formats_gt_261(self, string): result = parsing._guess_datetime_format(string) assert result is None
def test_guess_datetime_format_with_locale_specific_formats(string, fmt): result = parsing._guess_datetime_format(string) assert result == fmt
def test_guess_datetime_format_with_dayfirst_gt_261(self, dayfirst): ambiguous_string = '01/01/2011' result = parsing._guess_datetime_format(ambiguous_string, dayfirst=dayfirst) assert result is None
def test_guess_datetime_format_no_padding(string, fmt): # see gh-11142 result = parsing._guess_datetime_format(string) assert result == fmt
def test_guess_datetime_format_with_locale_specific_formats_gt_261( self, string): result = parsing._guess_datetime_format(string) assert result is None
def _guess_datetime_format_for_array(arr, **kwargs): # Try to guess the format based on the first non-NaN element non_nan_elements = notna(arr).nonzero()[0] if len(non_nan_elements): return _guess_datetime_format(arr[non_nan_elements[0]], **kwargs)
def test_guess_datetime_format_nopadding_gt_261(self, string): # GH 11142 result = parsing._guess_datetime_format(string) assert result is None