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

fix NaNtoMissing #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/fit_dataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# REVIEW THIS IN LIGHT OF NEW DATAFRAMES
# ========================================

import Base: isnan
import DataFrames: DataFrame, ncol, convert


Expand Down Expand Up @@ -269,16 +268,12 @@ function expand_categoricals!(df::DataFrame,categoricals::Array)
return expand_categoricals!(df, categoricalidxs)
end

# convert NaNs to NAs
# isnan(x::NAtype) = false
isnan(x::AbstractString) = false
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was type-piracy.
Fixed the problem that it was avoiding via adding isa Number check below

isnan(x::Union{T, Nothing}) where T = isnan(x.value)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a bad find and replace from a previous PR that replaced Nullable with Union{Nothing, T}
It was always nonsense.
idk why it wasn't breaking tests earlier


# same functionality as above.
function NaNs_to_Missing!(df::DataFrame)
m,n = size(df)
for j=1:n
df[!,j] = [ismissing(df[i,j]) || isnan(df[i,j]) ? missing : value for (i,value) in enumerate(df[:,j])];
df[!,j] = [(value isa Number && isnan(value)) ? missing : value for value in df[!,j]];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a bit simpler we only need the value, and adds the isa Number check

end
return df
end
Expand Down