Skip to content

Commit a217141

Browse files
committed
Fixed write_database logic
1 parent d16cd84 commit a217141

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/polars/data_frame.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ def write_database(table_name, connection = nil, if_table_exists: "fail")
998998
raise ArgumentError, "Table already exists"
999999
end
10001000

1001-
if if_table_exists != "append"
1001+
if !table_exists || if_table_exists == "replace"
10021002
mysql = connection.adapter_name.match?(/mysql|trilogy/i)
10031003
force = if_table_exists == "replace"
10041004
connection.create_table(table_name, id: false, force: force) do |t|

test/database_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_write_database_connection
103103

104104
def test_if_table_exists_fail
105105
df = Polars::DataFrame.new({"a" => ["one", "two", "three"], "b" => [1, 2, 3]})
106-
df.write_database("items")
106+
df.write_database("items", if_table_exists: "fail")
107107

108108
error = assert_raises(ArgumentError) do
109109
df.write_database("items", if_table_exists: "fail")
@@ -113,7 +113,7 @@ def test_if_table_exists_fail
113113

114114
def test_if_table_exists_append
115115
df = Polars::DataFrame.new({"a" => ["one", "two", "three"], "b" => [1, 2, 3]})
116-
df.write_database("items")
116+
df.write_database("items", if_table_exists: "append")
117117

118118
df2 = Polars::DataFrame.new({"a" => ["four", "five"], "b" => [4, 5]})
119119
df2.write_database("items", if_table_exists: "append")
@@ -123,7 +123,7 @@ def test_if_table_exists_append
123123

124124
def test_if_table_exists_replace
125125
df = Polars::DataFrame.new({"a" => ["one", "two", "three"], "b" => [1, 2, 3]})
126-
df.write_database("items")
126+
df.write_database("items", if_table_exists: "replace")
127127

128128
df2 = Polars::DataFrame.new({"a" => ["four", "five"], "b" => [4, 5]})
129129
df2.write_database("items", if_table_exists: "replace")
@@ -159,7 +159,7 @@ def test_write_database_types
159159
Polars::Series.new("uint32", [(1 << 32) - 1], dtype: Polars::UInt32),
160160
# Polars::Series.new("uint64", [(1 << 64) - 1], dtype: Polars::UInt64),
161161
Polars::Series.new("string", ["str"], dtype: Polars::String),
162-
Polars::Series.new("time", [Time.now], dtype: Polars::Time)
162+
Polars::Series.new("time", [time], dtype: Polars::Time)
163163
])
164164
df.write_database("items")
165165

0 commit comments

Comments
 (0)