Skip to content

Commit 7ecf3d4

Browse files
reset dec='\0' to detect numbers while dec is undecided
1 parent 392a321 commit 7ecf3d4

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
1. In `DT[, variable := value]`, when value is class `POSIXlt`, we automatically coerce it to class `POSIXct` instead, [#1724](https://github.com/Rdatatable/data.table/issues/1724). Thanks to @linzhp for the report, and Benjamin Schwendinger for the fix.
88

9+
## BUG FIXES
10+
11+
1. `fread()` automatically detects timestamps with microseconds again, [#6440](https://github.com/Rdatatable/data.table/issues/6440). This was a regression due to interference with new `dec='auto'` support. Thanks @kav2k for the concise report and @MichaelChirico for the fix.
12+
913
## NOTES
1014

1115
1. Tests run again when some Suggests packages are missing, [#6411](https://github.com/Rdatatable/data.table/issues/6411). Thanks @aadler for the note and @MichaelChirico for the fix.

src/fread.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ static void parse_iso8601_timestamp(FieldParseContext *ctx)
10381038
if (second == NA_FLOAT64 || second < 0 || second >= 60)
10391039
goto fail;
10401040

1041-
if (*ch == 'Z') {
1041+
if (*ch == 'Z') {
10421042
ch++; // "Zulu time"=UTC
10431043
} else {
10441044
if (*ch == ' ')
@@ -1075,7 +1075,6 @@ static void parse_iso8601_timestamp(FieldParseContext *ctx)
10751075

10761076
date_only:
10771077

1078-
//Rprintf("date=%d\thour=%d\tz_hour=%d\tminute=%d\ttz_minute=%d\tsecond=%.1f\n", date, hour, tz_hour, minute, tz_minute, second);
10791078
// cast upfront needed to prevent silent overflow
10801079
*target = 86400*(double)date + 3600*(hour - tz_hour) + 60*(minute - tz_minute) + second;
10811080

@@ -1236,9 +1235,13 @@ static int detect_types( const char **pch, int8_t type[], int ncol, bool *bumped
12361235
}
12371236
}
12381237
ch = fieldStart;
1239-
if (autoDec && IS_DEC_TYPE(tmpType[field]) && dec == '.') { // . didn't parse a double; try ,
1240-
dec = ',';
1241-
continue;
1238+
if (autoDec && IS_DEC_TYPE(tmpType[field])) {
1239+
if (dec == '.') { // '.' didn't parse a double; try ','
1240+
dec = ',';
1241+
continue; // i.e., restart since tmpType not incremented
1242+
} else if (dec == ',') { // ',' didn't parse a double either; reset
1243+
dec = '\0';
1244+
}
12421245
}
12431246
while (++tmpType[field]<CT_STRING && disabled_parsers[tmpType[field]]) {};
12441247
*bumped = true;

src/fread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ typedef enum {
3636
NUMTYPE // placeholder for the number of types including drop; used for allocation and loop bounds
3737
} colType;
3838

39-
#define IS_DEC_TYPE(x) ((x) == CT_FLOAT64 || (x) == CT_FLOAT64_EXT) // types where dec matters
39+
#define IS_DEC_TYPE(x) ((x) == CT_FLOAT64 || (x) == CT_FLOAT64_EXT || (x) == CT_ISO8601_TIME) // types where dec matters
4040

4141
extern int8_t typeSize[NUMTYPE];
4242
extern const char typeName[NUMTYPE][10];

0 commit comments

Comments
 (0)