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

Allow single column name for cols #28

Merged
merged 4 commits into from
Feb 25, 2021
Merged

Allow single column name for cols #28

merged 4 commits into from
Feb 25, 2021

Conversation

bencottier
Copy link
Contributor

@bencottier bencottier commented Feb 23, 2021

Closes #26

This is the behaviour using a single column name (i.e. not a list):

  • apply returns the single transformed column, "unwrapped"
    • Except for LinearCombination, because it always produces one column anyway
  • apply! allows it, but gives the same result

@codecov
Copy link

codecov bot commented Feb 23, 2021

Codecov Report

Merging #28 (ad25020) into main (6c43de4) will decrease coverage by 1.25%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   95.79%   94.54%   -1.26%     
==========================================
  Files           9        9              
  Lines         119      110       -9     
==========================================
- Hits          114      104      -10     
- Misses          5        6       +1     
Impacted Files Coverage Δ
src/utils.jl 37.50% <75.00%> (+37.50%) ⬆️
src/linear_combination.jl 100.00% <100.00%> (ø)
src/transformers.jl 100.00% <100.00%> (ø)
src/scaling.jl 96.15% <0.00%> (-0.52%) ⬇️
src/power.jl 100.00% <0.00%> (ø)
src/periodic.jl 100.00% <0.00%> (ø)
src/one_hot_encoding.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6c43de4...7014619. Read the comment docs.

@@ -64,6 +64,10 @@ Applies the [`LinearCombination`](@ref) to each of the specified cols in `x`.
If no `cols` are specified, then the [`LinearCombination`](@ref) is applied to all columns.
"""
function apply(x, LC::LinearCombination; cols=nothing)
if cols isa Union{Symbol, AbstractString} # want same behaviour for single column
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use multiple dispatch here instead wich is generally more performant

function apply(x, LC::LinearCombination; cols::Union{Symbol, AbstractString})
     apply(x, LC; cols=[cols]
 end

Copy link
Member

Choose a reason for hiding this comment

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

Julia doesn't dispatch on the keyword args though https://docs.julialang.org/en/v1/manual/methods/#Note-on-Optional-and-keyword-Arguments

Methods are dispatched based only on positional arguments, with keyword arguments processed after the matching method is identified.

So you'll need something like a _to_vec method

_to_vec(x::AbstractArray) = x
_to_vec(x) = [x]

Copy link
Contributor Author

@bencottier bencottier Feb 24, 2021

Choose a reason for hiding this comment

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

So you'll need something like a _to_vec method

Just note I'm trying to allow cols as any collection including Tuple, so I want to dispatch the opposite way on Union{Symbol, AbstractString} rather than AbstractArray.

Copy link
Contributor Author

@bencottier bencottier Feb 24, 2021

Choose a reason for hiding this comment

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

Just note I'm trying to allow cols as any collection including Tuple, so I want to dispatch the opposite way on Union{Symbol, AbstractString} rather than AbstractArray.

Maybe just Union{Tuple, AbstractArray} is good enough and clearer, actually.

test/linear_combination.jl Show resolved Hide resolved
test/one_hot_encoding.jl Show resolved Hide resolved
test/linear_combination.jl Show resolved Hide resolved
src/transformers.jl Outdated Show resolved Hide resolved
src/utils.jl Show resolved Hide resolved
src/transformers.jl Show resolved Hide resolved
bencottier and others added 4 commits February 25, 2021 14:19
- `apply` returns the unwrapped column (except LinearCombination)
- `apply!` gives the same result
@bencottier bencottier merged commit 7f95dd5 into main Feb 25, 2021
@bencottier bencottier deleted the bc/single-cols branch February 25, 2021 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have apply return single column array when cols is a single column name
4 participants