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

Adding vector through direct assignment fails when DataFrame is empty #522

Open
dipanm opened this issue Jan 5, 2020 · 0 comments
Open

Comments

@dipanm
Copy link

dipanm commented Jan 5, 2020

Here is the code that works:

df = Daru::DataFrame.new({:name => ['john'], :address => ['NY'], :age => [22]}, :index => [1])
 => #<Daru::DataFrame(1x3)>
            name address     age
       1    john      NY      22 

df[:id] = 101
=> 101 
 df
 => #<Daru::DataFrame(1x4)>
            name address     age      id
       1    john      NY      22     101 

So when we add value in a non-existant vector - it essentially creates a new vector and fills the value.

However, the same doesn't work when the existing DF is empty.

df = Daru::DataFrame.new({:name => [], :address => [], :age => []}, :index => [])
 => #<Daru::DataFrame(0x3)>
    name address     age 
df[:id] = 0
NoMethodError: undefined method `to_a' for 0:Fixnum
	from /Users/Dipan/.rvm/gems/ruby-2.2.5/gems/daru-0.2.2/lib/daru/dataframe.rb:2629:in `insert_vector_in_empty'
	from /Users/Dipan/.rvm/gems/ruby-2.2.5/gems/daru-0.2.2/lib/daru/dataframe.rb:2589:in `insert_or_modify_vector'
	from /Users/Dipan/.rvm/gems/ruby-2.2.5/gems/daru-0.2.2/lib/daru/dataframe.rb:2487:in `dispatch_to_axis'
	from /Users/Dipan/.rvm/gems/ruby-2.2.5/gems/daru-0.2.2/lib/daru/dataframe.rb:537:in `[]='
	from (irb):7
	from /Users/Dipan/.rvm/rubies/ruby-2.2.5/bin/irb:11:in `<main>'

A typical expectation would be if the df empty is empty it should just add a vector and return without adding any row. At least don't face an unhandled exception.

Any help?

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

No branches or pull requests

1 participant