Skip to content

Commit 21cf1ac

Browse files
committed
Support mm-yyyy along with mm-dd-yyyy
1 parent 14dad59 commit 21cf1ac

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

pandas/_libs/tslibs/parsing.pyx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ DEF delimiters = b' /-\\'
6262
DEF MAX_DAYS_IN_MONTH = 31
6363
DEF MAX_MONTH = 12
6464

65+
cdef bint _is_not_delimiter(const char ch):
66+
return strchr(delimiters, ch) == NULL
67+
6568
cdef inline int _parse_2digit(const char* s):
6669
cdef int result = 0
6770
result += getdigit_ascii(s[0], -10) * 10
@@ -84,13 +87,21 @@ cdef object parse_slashed_date(object date_string, bint dayfirst,
8487
int day, month, year
8588

8689
buf = get_c_string_buf_and_size(date_string, &length)
87-
if length != 10 or strchr(delimiters, buf[2]) == NULL \
88-
or strchr(delimiters, buf[5]) == NULL:
90+
if length == 10:
91+
if _is_not_delimiter(buf[2]) or _is_not_delimiter(buf[5]):
92+
return None
93+
month = _parse_2digit(buf)
94+
day = _parse_2digit(buf + 3)
95+
year = _parse_4digit(buf + 6)
96+
elif length == 7:
97+
if _is_not_delimiter(buf[2]):
98+
return None
99+
month = _parse_2digit(buf)
100+
day = 1
101+
year = _parse_4digit(buf + 3)
102+
else:
89103
return None
90104

91-
month = _parse_2digit(buf)
92-
day = _parse_2digit(buf + 3)
93-
year = _parse_4digit(buf + 6)
94105
if month < 0 or day < 0 or year < 0:
95106
# some part is not an integer, so it's not a mm/dd/yyyy date
96107
return None

0 commit comments

Comments
 (0)