@@ -43,24 +43,19 @@ DropMissing(cols::T...) where {T<:Col} = DropMissing(colspec(cols))
43
43
44
44
isrevertible (:: Type{<:DropMissing} ) = true
45
45
46
- _ftrans (:: DropMissing{AllSpec} , snames) = Filter (row -> all (! ismissing, row))
47
- _ftrans (:: DropMissing , snames) = Filter (row -> all (! ismissing, row[nm] for nm in snames))
48
-
49
- # nonmissing
50
- _nonmissing (:: Type{T} , x) where {T} = x
51
- _nonmissing (:: Type{Union{Missing,T}} , x) where {T} = collect (T, x)
52
- _nonmissing (:: Type{Missing} , x) = []
53
- _nonmissing (x) = _nonmissing (eltype (x), x)
54
-
55
46
function preprocess (transform:: DropMissing , table)
56
- schema = Tables. schema (table)
57
- names = schema. names
47
+ names = Tables. schema (table). names
58
48
snames = choose (transform. colspec, names)
59
- ftrans = _ftrans (transform, snames)
49
+ ftrans = Filter (row -> all ( ! ismissing (row[nm]) for nm in snames) )
60
50
fprep = preprocess (ftrans, table)
61
51
ftrans, fprep, snames
62
52
end
63
53
54
+ _nonmissing (x) = _nonmissing (eltype (x), x)
55
+ _nonmissing (:: Type{T} , x) where {T} = x
56
+ _nonmissing (:: Type{Missing} , x) = []
57
+ _nonmissing (:: Type{Union{Missing,T}} , x) where {T} = collect (T, x)
58
+
64
59
function applyfeat (:: DropMissing , feat, prep)
65
60
# apply filter transform
66
61
ftrans, fprep, snames = prep
@@ -69,28 +64,28 @@ function applyfeat(::DropMissing, feat, prep)
69
64
# drop Missing type
70
65
cols = Tables. columns (newfeat)
71
66
names = Tables. columnnames (cols)
72
- columns = map (names) do nm
73
- x = Tables. getcolumn (cols, nm )
74
- nm ∈ snames ? _nonmissing (x) : x
67
+ columns = map (names) do name
68
+ x = Tables. getcolumn (cols, name )
69
+ name ∈ snames ? _nonmissing (x) : x
75
70
end
76
71
𝒯 = (; zip (names, columns)... )
77
72
newfeat = 𝒯 |> Tables. materializer (feat)
78
73
79
74
# original column types
80
75
types = Tables. schema (feat). types
81
76
82
- newfeat, (ftrans, ffcache, types)
77
+ newfeat, (ftrans, ffcache, snames, types)
83
78
end
84
79
85
80
function revertfeat (:: DropMissing , newfeat, fcache)
86
- ftrans, ffcache, types = fcache
81
+ ftrans, ffcache, snames, types = fcache
87
82
88
83
# reintroduce Missing type
89
84
cols = Tables. columns (newfeat)
90
85
names = Tables. columnnames (cols)
91
- columns = map (zip ( types, names)) do ( T, nm)
92
- x = Tables. getcolumn (cols, nm )
93
- collect (T, x)
86
+ columns = map (types, names) do T, name
87
+ x = Tables. getcolumn (cols, name )
88
+ name ∈ snames ? collect (T, x) : x
94
89
end
95
90
𝒯 = (; zip (names, columns)... )
96
91
ofeat = 𝒯 |> Tables. materializer (newfeat)
0 commit comments