Skip to content

fread's na.strings argument should handle values like "-999" #1314

Closed

Description

@arunsrinivasan

With @dselivanov's excellent PR, providing na.strings value doesn't result in columns being coerced to character anymore.

There's still one point left to address though, as mentioned under that PR -- cases like these:

require(data.table)
DT = data.table(a=9:10, b=9:10 + 0.1, c=as.logical(0:1))
text = do.call("paste", c(DT, collapse="\n", sep=","))
ans1 = fread(text, na.strings=c("9", "9.1", "FALSE"))
#    V1   V2    V3
#1:  9  9.1 FALSE
#2: 10 10.1  TRUE

sapply(ans1, class)
#         V1        V2        V3 
#  "integer" "numeric" "logical" 

# whereas read.table() gives
ans2 = read.table(text=text, na.strings=c("9", "9.1", "FALSE"), sep=",", header=FALSE)
#   V1   V2   V3
#1 NA   NA   NA
#2 10 10.1 TRUE

sapply(ans2, class)
#         V1        V2        V3 
#  "integer" "numeric" "logical" 

read.table() handles them correctly.

Activity

  1. added this to the v1.9.6 milestone on Sep 9, 2015
  2. arunsrinivasan commented on Sep 9, 2015

    @arunsrinivasan
    MemberAuthor

    Benchmarks on 0.1, 0.01, 0.3 and na_rich scenarios after raising the if-statement.

    #    File thisFR stable (6f99651)
    #     0.1 51.421 48.068
    #    0.01 51.776 54.264
    #   0.001 52.255 50.820
    #     0.3 48.150 47.930
    # na_rich 17.570 17.354
  3. dselivanov commented on Sep 11, 2015

    @dselivanov

    @arunsrinivasan, nice catch! Surprised by this timings!

  4. arunsrinivasan commented on Sep 11, 2015

    @arunsrinivasan
    MemberAuthor

    @dselivanov thanks. I wasn't clear with what the timings were. It's without na.strings=., to test default scenario. I'll add benchmarks with the arg later. I'd guess there'd be some hit. But not sure yet how to avoid that with the functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions