Skip to content

Commit

Permalink
fixes #329. DataFrame.new creates empty dataframe with default argume…
Browse files Browse the repository at this point in the history
…nt empty Hash. (#395)
  • Loading branch information
parthm authored and v0dro committed Aug 26, 2017
1 parent 3e9e023 commit 4879ff3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/daru/dataframe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ def from_vector_rows source, opts
# Default to *true*.
#
# == Usage
#
# df = Daru::DataFrame.new
# # =>
# # <Daru::DataFrame(0x0)>
# # Creates an empty DataFrame with no rows or columns.
#
# df = Daru::DataFrame.new({}, order: [:a, :b])
# #<Daru::DataFrame(0x2)>
# a b
# # Creates a DataFrame with no rows and columns :a and :b
#
# df = Daru::DataFrame.new({a: [1,2,3,4], b: [6,7,8,9]}, order: [:b, :a],
# index: [:a, :b, :c, :d], name: :spider_man)
#
Expand Down Expand Up @@ -329,7 +340,7 @@ def from_vector_rows source, opts
# # 1 4 14 44
# # 2 5 15 55

def initialize source, opts={} # rubocop:disable Metrics/MethodLength
def initialize source={}, opts={} # rubocop:disable Metrics/MethodLength
vectors, index = opts[:order], opts[:index] # FIXME: just keyword arges after Ruby 2.1
@data = []
@name = opts[:name]
Expand Down
9 changes: 8 additions & 1 deletion spec/dataframe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,15 @@
end

context "#initialize" do

it "initializes an empty DataFrame with no arguments" do
df = Daru::DataFrame.new
expect(df.nrows).to eq(0)
expect(df.ncols).to eq(0)
end

context Daru::Index do
it "initializes an empty DataFrame" do
it "initializes an empty DataFrame with empty source arg" do
df = Daru::DataFrame.new({}, order: [:a, :b])

expect(df.vectors).to eq(Daru::Index.new [:a, :b])
Expand Down

0 comments on commit 4879ff3

Please sign in to comment.