Skip to content

Commit fffb34c

Browse files
committed
✨ Fix the union types
1 parent 76bd4ed commit fffb34c

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/encoders/missingness_encoding/missingness_encoding.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ function missingness_encoder_fit(
3535
Char => 'm',
3636
),
3737
)
38-
supportedtypes = Union{Char, AbstractString, Number}
38+
supportedtypes_list = [Char, AbstractString, Number]
39+
supportedtypes = Union{supportedtypes_list...}
3940

4041
# 1. Define feature mapper
4142
function feature_mapper(col, name)
@@ -50,7 +51,7 @@ function missingness_encoder_fit(
5051

5152
# Ensure label_for_missing keys are valid types
5253
for possible_col_type in keys(label_for_missing)
53-
if !(possible_col_type in union_types(supportedtypes))
54+
if !(possible_col_type in supportedtypes_list)
5455
throw(ArgumentError(VALID_TYPES_NEW_VAL_ME(possible_col_type)))
5556
end
5657
end
@@ -66,7 +67,7 @@ function missingness_encoder_fit(
6667

6768
# Get ancestor type of column
6869
elgrandtype = nothing
69-
for allowed_type in union_types(supportedtypes)
70+
for allowed_type in supportedtypes_list
7071
if col_type <: allowed_type
7172
elgrandtype = allowed_type
7273
break

src/transformers/cardinality_reducer/cardinality_reducer.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function cardinality_reducer_fit(
4141
Char => 'O',
4242
),
4343
)
44-
supportedtypes = Union{Char, AbstractString, Number}
44+
supportedtypes_list = [Char, AbstractString, Number]
45+
supportedtypes = Union{supportedtypes_list...}
4546

4647
# 1. Define feature mapper
4748
function feature_mapper(col, name)
@@ -57,7 +58,7 @@ function cardinality_reducer_fit(
5758

5859
# Ensure label_for_infrequent keys are valid types
5960
for possible_col_type in keys(label_for_infrequent)
60-
if !(possible_col_type in union_types(supportedtypes))
61+
if !(possible_col_type in supportedtypes_list)
6162
throw(ArgumentError(VALID_TYPES_NEW_VAL(possible_col_type)))
6263
end
6364
end
@@ -71,7 +72,7 @@ function cardinality_reducer_fit(
7172

7273
# Get ancestor type of column
7374
elgrandtype = nothing
74-
for allowed_type in union_types(supportedtypes)
75+
for allowed_type in supportedtypes_list
7576
if col_type <: allowed_type
7677
elgrandtype = allowed_type
7778
break

src/utils.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# To go from e.g., Union{Integer, String} to (Integer, String)
2-
union_types(x::Union) = (x.a, union_types(x.b)...)
3-
union_types(x::Type) = (x,)
1+
# add utility functions here

test/transformers/cardinality_reducer.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using MLJTransforms: union_types, cardinality_reducer_fit, cardinality_reducer_transform
1+
using MLJTransforms: cardinality_reducer_fit, cardinality_reducer_transform
2+
23

3-
@testset "Union_types" begin
4-
@test union_types(Union{Integer, String}) == (Integer, String)
5-
end
64

75
@testset "Throws errors when needed" begin
86
@test_throws ArgumentError begin

0 commit comments

Comments
 (0)