Skip to content

Commit

Permalink
Revert "reset dec='\0' to detect numbers while dec is undecided"
Browse files Browse the repository at this point in the history
This reverts commit 7ecf3d4.
  • Loading branch information
MichaelChirico committed Aug 30, 2024
1 parent 7ecf3d4 commit 80c46a0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
4 changes: 0 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

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.

## BUG FIXES

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.

## NOTES

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.
Expand Down
13 changes: 5 additions & 8 deletions src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ static void parse_iso8601_timestamp(FieldParseContext *ctx)
if (second == NA_FLOAT64 || second < 0 || second >= 60)
goto fail;

if (*ch == 'Z') {
if (*ch == 'Z') {
ch++; // "Zulu time"=UTC
} else {
if (*ch == ' ')
Expand Down Expand Up @@ -1075,6 +1075,7 @@ static void parse_iso8601_timestamp(FieldParseContext *ctx)

date_only:

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

Expand Down Expand Up @@ -1235,13 +1236,9 @@ static int detect_types( const char **pch, int8_t type[], int ncol, bool *bumped
}
}
ch = fieldStart;
if (autoDec && IS_DEC_TYPE(tmpType[field])) {
if (dec == '.') { // '.' didn't parse a double; try ','
dec = ',';
continue; // i.e., restart since tmpType not incremented
} else if (dec == ',') { // ',' didn't parse a double either; reset
dec = '\0';
}
if (autoDec && IS_DEC_TYPE(tmpType[field]) && dec == '.') { // . didn't parse a double; try ,
dec = ',';
continue;
}
while (++tmpType[field]<CT_STRING && disabled_parsers[tmpType[field]]) {};
*bumped = true;
Expand Down
2 changes: 1 addition & 1 deletion src/fread.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ typedef enum {
NUMTYPE // placeholder for the number of types including drop; used for allocation and loop bounds
} colType;

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

extern int8_t typeSize[NUMTYPE];
extern const char typeName[NUMTYPE][10];
Expand Down

0 comments on commit 80c46a0

Please sign in to comment.