Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NA is still converted to NaN even in a string column #169

Open
indeedhat opened this issue Oct 14, 2021 · 2 comments
Open

NA is still converted to NaN even in a string column #169

indeedhat opened this issue Oct 14, 2021 · 2 comments
Labels

Comments

@indeedhat
Copy link

Issue

It doesn't seem to matter what the column type is in the data frame NA will always get converted to NaN.

Expected Behavior

NA would only be converted to NaN in int and float columns

Actual Behaviour

NA is converted to NaN regardless of the type

Example

Take this modified version of some data from the README

package main

import (
	"fmt"
	"strings"

	"github.com/go-gota/gota/dataframe"
	"github.com/go-gota/gota/series"
)

const ExampleData = `
Country,Region,Date,Age,Amount,Id
"United States",US,2012-02-01,50,112.1,01234
"United States",US,2012-02-01,32,321.31,54320
"United Kingdom",GB,2012-02-01,17,18.2,12345
"United States",NA,2012-02-01,32,321.31,54320
"United States","NA",2012-02-01,17,321.31,54320
"United Kingdom",GB,2012-02-01,NA,18.2,12345
"United States",NA,2012-02-01,32,321.31,54320
Spain,EU,2012-02-01,66,555.42,00241
`

func main() {
    frame := dataframe.ReadCSV(
        strings.NewReader(ExampleData),
        dataframe.WithTypes(map[string]series.Type{
            "Age": series.String,
        }),
    )

    fmt.Println(frame)
}

which produces the following output

[8x6] DataFrame

    Country        Region   Date       Age      Amount     Id
 0: United States  US       2012-02-01 50       112.100000 1234
 1: United States  US       2012-02-01 32       321.310000 54320
 2: United Kingdom GB       2012-02-01 17       18.200000  12345
 3: United States  NaN      2012-02-01 32       321.310000 54320
 4: United States  NaN      2012-02-01 17       321.310000 54320
 5: United Kingdom GB       2012-02-01 NaN      18.200000  12345
 6: United States  NaN      2012-02-01 32       321.310000 54320
 7: Spain          EU       2012-02-01 66       555.420000 241
    <string>       <string> <string>   <string> <float>    <int>

In both colums:

  • Region with an implicit string type
  • Age where i have explicitly set the type to string

The string value NA is converted

@prliu
Copy link
Contributor

prliu commented Nov 26, 2021

This problem is due to the ReadCSV function converting the "NA" string to "NaN" before we assign a data type to the column, it should be tagged as a bug.

I'm trying to make a patch for this issue.

prliu added a commit to prliu/gota that referenced this issue Nov 26, 2021
prliu added a commit to prliu/gota that referenced this issue Nov 26, 2021
@indeedhat
Copy link
Author

Much appreciated, i look forward to this being merged :)

@chrmang chrmang added the bug label Jan 8, 2022
shivamthapar added a commit to runway/gota that referenced this issue Nov 20, 2024
shivamthapar added a commit to runway/gota that referenced this issue Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants