Skip to content

Commit b0cd67c

Browse files
author
MarcoGorelli
committed
rename, document better
1 parent f528fed commit b0cd67c

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

pandas/_libs/tslibs/np_datetime.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ cdef int64_t convert_reso(
123123

124124
cdef extern from "src/datetime/np_datetime_strings.h":
125125
cdef enum Exact:
126-
INEXACT_MATCH
126+
PARTIAL_MATCH
127127
EXACT_MATCH
128128
NO_MATCH

pandas/_libs/tslibs/src/datetime/np_datetime_strings.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
141141
while (sublen > 0 && isspace(*substr)) {
142142
++substr;
143143
--sublen;
144-
if (exact == INEXACT_MATCH && !format_len) {
144+
if (exact == PARTIAL_MATCH && !format_len) {
145145
goto finish;
146146
}
147147
if (compare_format(&format, &format_len, " ", 1, exact)) {
@@ -160,7 +160,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
160160
}
161161

162162
/* PARSE THE YEAR (4 digits) */
163-
if (exact == INEXACT_MATCH && !format_len) {
163+
if (exact == PARTIAL_MATCH && !format_len) {
164164
goto finish;
165165
}
166166
if (compare_format(&format, &format_len, "%Y", 2, exact)) {
@@ -210,7 +210,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
210210
++substr;
211211
--sublen;
212212

213-
if (exact == INEXACT_MATCH && !format_len) {
213+
if (exact == PARTIAL_MATCH && !format_len) {
214214
goto finish;
215215
}
216216
if (compare_format(&format, &format_len, &ymd_sep, 1, exact)) {
@@ -223,7 +223,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
223223
}
224224

225225
/* PARSE THE MONTH */
226-
if (exact == INEXACT_MATCH && !format_len) {
226+
if (exact == PARTIAL_MATCH && !format_len) {
227227
goto finish;
228228
}
229229
if (compare_format(&format, &format_len, "%m", 2, exact)) {
@@ -272,7 +272,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
272272
}
273273
++substr;
274274
--sublen;
275-
if (exact == INEXACT_MATCH && !format_len) {
275+
if (exact == PARTIAL_MATCH && !format_len) {
276276
goto finish;
277277
}
278278
if (compare_format(&format, &format_len, &ymd_sep, 1, exact)) {
@@ -281,7 +281,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
281281
}
282282

283283
/* PARSE THE DAY */
284-
if (exact == INEXACT_MATCH && !format_len) {
284+
if (exact == PARTIAL_MATCH && !format_len) {
285285
goto finish;
286286
}
287287
if (compare_format(&format, &format_len, "%d", 2, exact)) {
@@ -326,7 +326,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
326326
if ((*substr != 'T' && *substr != ' ') || sublen == 1) {
327327
goto parse_error;
328328
}
329-
if (exact == INEXACT_MATCH && !format_len) {
329+
if (exact == PARTIAL_MATCH && !format_len) {
330330
goto finish;
331331
}
332332
if (compare_format(&format, &format_len, substr, 1, exact)) {
@@ -336,7 +336,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
336336
--sublen;
337337

338338
/* PARSE THE HOURS */
339-
if (exact == INEXACT_MATCH && !format_len) {
339+
if (exact == PARTIAL_MATCH && !format_len) {
340340
goto finish;
341341
}
342342
if (compare_format(&format, &format_len, "%H", 2, exact)) {
@@ -385,7 +385,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
385385
if (sublen == 0 || !isdigit(*substr)) {
386386
goto parse_error;
387387
}
388-
if (exact == INEXACT_MATCH && !format_len) {
388+
if (exact == PARTIAL_MATCH && !format_len) {
389389
goto finish;
390390
}
391391
if (compare_format(&format, &format_len, ":", 1, exact)) {
@@ -399,7 +399,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
399399
}
400400

401401
/* PARSE THE MINUTES */
402-
if (exact == INEXACT_MATCH && !format_len) {
402+
if (exact == PARTIAL_MATCH && !format_len) {
403403
goto finish;
404404
}
405405
if (compare_format(&format, &format_len, "%M", 2, exact)) {
@@ -437,7 +437,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
437437
/* If we make it through this condition block, then the next
438438
* character is a digit. */
439439
if (has_hms_sep && *substr == ':') {
440-
if (exact == INEXACT_MATCH && !format_len) {
440+
if (exact == PARTIAL_MATCH && !format_len) {
441441
goto finish;
442442
}
443443
if (compare_format(&format, &format_len, ":", 1, exact)) {
@@ -455,7 +455,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
455455
}
456456

457457
/* PARSE THE SECONDS */
458-
if (exact == INEXACT_MATCH && !format_len) {
458+
if (exact == PARTIAL_MATCH && !format_len) {
459459
goto finish;
460460
}
461461
if (compare_format(&format, &format_len, "%S", 2, exact)) {
@@ -486,7 +486,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
486486
if (sublen > 0 && *substr == '.') {
487487
++substr;
488488
--sublen;
489-
if (exact == INEXACT_MATCH && !format_len) {
489+
if (exact == PARTIAL_MATCH && !format_len) {
490490
goto finish;
491491
}
492492
if (compare_format(&format, &format_len, ".", 1, exact)) {
@@ -498,7 +498,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
498498
}
499499

500500
/* PARSE THE MICROSECONDS (0 to 6 digits) */
501-
if (exact == INEXACT_MATCH && !format_len) {
501+
if (exact == PARTIAL_MATCH && !format_len) {
502502
goto finish;
503503
}
504504
if (compare_format(&format, &format_len, "%f", 2, exact)) {
@@ -568,7 +568,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
568568
while (sublen > 0 && isspace(*substr)) {
569569
++substr;
570570
--sublen;
571-
if (exact == INEXACT_MATCH && !format_len) {
571+
if (exact == PARTIAL_MATCH && !format_len) {
572572
goto finish;
573573
}
574574
if (compare_format(&format, &format_len, " ", 1, exact)) {
@@ -586,7 +586,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
586586

587587
/* UTC specifier */
588588
if (*substr == 'Z') {
589-
if (exact == INEXACT_MATCH && !format_len) {
589+
if (exact == PARTIAL_MATCH && !format_len) {
590590
goto finish;
591591
}
592592
if (compare_format(&format, &format_len, "%z", 2, exact)) {
@@ -611,7 +611,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
611611
--sublen;
612612
}
613613
} else if (*substr == '-' || *substr == '+') {
614-
if (exact == INEXACT_MATCH && !format_len) {
614+
if (exact == PARTIAL_MATCH && !format_len) {
615615
goto finish;
616616
}
617617
if (compare_format(&format, &format_len, "%z", 2, exact)) {
@@ -700,7 +700,7 @@ int parse_iso_8601_datetime(const char *str, int len, int want_exc,
700700
while (sublen > 0 && isspace(*substr)) {
701701
++substr;
702702
--sublen;
703-
if (exact == INEXACT_MATCH && !format_len) {
703+
if (exact == PARTIAL_MATCH && !format_len) {
704704
goto finish;
705705
}
706706
if (compare_format(&format, &format_len, " ", 1, exact)) {

pandas/_libs/tslibs/src/datetime/np_datetime_strings.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@ This file implements string parsing and creation for NumPy datetime.
2626
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
2727
#endif // NPY_NO_DEPRECATED_API
2828

29+
/* 'exact' can be one of three values:
30+
* * PARTIAL_MATCH : Only require a partial match with 'format'.
31+
* For example, if the string is '2020-01-01 05:00:00' and
32+
* 'format' is '%Y-%m-%d', then parse '2020-01-01';
33+
* * EXACT_MATCH : require an exact match with 'format'. If the
34+
* string is '2020-01-01', then the only format which will
35+
* be able to parse it without error is '%Y-%m-%d';
36+
* * NO_MATCH: don't require any match - parse without comparing
37+
* with 'format'.
38+
*/
2939
enum Exact {
30-
INEXACT_MATCH,
40+
PARTIAL_MATCH,
3141
EXACT_MATCH,
3242
NO_MATCH
3343
};

0 commit comments

Comments
 (0)