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 vector_sum to ignore nils #391 #398

Conversation

baarkerlounger
Copy link
Contributor

Copy link
Collaborator

@zverok zverok left a comment

Choose a reason for hiding this comment

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

Turns out it would be more tricky :(

vecs ||= numeric_vectors
sum = Daru::Vector.new [0]*@size, index: @index, name: @name, dtype: @dtype

replace_nils(0) if skipnil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unfortunately, there is a problem with this approach. replace_nils(0) (as well as replace_values) changes the source DF. The result would be the following:

df = Daru::DataFrame.new({
        a: [1,    2,          3,   nil,        Float::NAN, nil, 1,   7],
        b: [:a,  :b,          nil, Float::NAN, nil,        3,   5,   8],
        c: ['a',  Float::NAN, 3,   4,          3,          5,   nil, 7]
    })
# => #<Daru::DataFrame(8x3)>
#       a   b   c
#   0   1   a   a
#   1   2   b NaN
#   2   3 nil   3
#   3 nil NaN   4
#   4 NaN nil   3
#   5 nil   3   5
#   6   1   5 nil
#   7   7   8   7 

df.vector_sum(nil, true)
# => #<Daru::Vector(8)>
#   0   1
#   1   2
#   2   3
#   3   0
#   4 NaN
#   5   0
#   6   1
#   7   7 

df
# => #<Daru::DataFrame(8x3)>
#       a   b   c
#   0   1   a   a
#   1   2   b NaN
#   2   3   0   3
#   3   0 NaN   4
#   4 NaN   0   3
#   5   0   3   5
#   6   1   5   0
#   7   7   8   7 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zverok You're right, can fix by making it clone and sum or we can go with @parthm's approach. What do you think?

@baarkerlounger baarkerlounger deleted the dataframe_vector_sum_ignores_nils branch August 28, 2017 21:32
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.

2 participants