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

parse_to_columns should generate at least one row for a non-match #7171

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ parse_to_columns table input_column_id pattern="." case_sensitivity=Case_Sensiti
column = table.at input_column_id

new_table = Value_Type.expect_text column <|
fan_out_to_rows_and_columns table input_column_id fun column_names on_problems=on_problems
fan_out_to_rows_and_columns table input_column_id fun column_names at_least_one_row=True on_problems=on_problems
if parse_values then new_table.parse on_problems=on_problems else new_table

## PRIVATE
Expand Down
13 changes: 9 additions & 4 deletions test/Table_Tests/src/In_Memory/Split_Tokenize_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,25 @@ spec =
actual.should_equal expected

Test.specify "input with no matches" <|
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"]]
expected = Table.from_rows ["foo", "bar", "baz"] []
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"], ["xx", "q12", "yy"], ["xxx", "34r", "yyyy"]]
expected = Table.from_rows ["foo", "bar", "baz"] [["x", Nothing, "y"], ["xx", 12, "yy"], ["xxx", 34, "yyyy"]]
actual = t.parse_to_columns "bar" "\d+"
actual.should_equal expected

t2 = Table.new [["amount", ["$1.23B", "$1.3M", "$2.32M $3.43B", "None"]]]
expected2 = Table.from_rows ["Raised", "Scale"] [[1.23, "B"], [1.3, "M"], [2.32, "M"], [3.43, "B"], [Nothing, Nothing]]
actual2 = t2.parse_to_columns "amount" "\$(?<Raised>\d+(?:.\d+)?)(?<Scale>B|M)"
actual2.should_equal expected2

Test.specify "input with no matches, with regex groups" <|
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"]]
expected = Table.from_rows ["foo", "bar 1", "bar 2", "baz"] []
expected = Table.from_rows ["foo", "bar 1", "bar 2", "baz"] [["x", Nothing, Nothing, "y"]]
actual = t.parse_to_columns "bar" "(\d)(\d)"
actual.should_equal expected

Test.specify "input with no matches, with named and unnamed regex groups" <|
t = Table.from_rows ["foo", "bar", "baz"] [["x", "a", "y"]]
expected = Table.from_rows ["foo", "quux", "bar 1", "foo 1", "bar 2", "baz"] []
expected = Table.from_rows ["foo", "quux", "bar 1", "foo 1", "bar 2", "baz"] [["x", Nothing, Nothing, Nothing, Nothing, "y"]]
actual = t.parse_to_columns "bar" "(?<quux>)(\d)(?<foo>\d)(\d)"
actual.should_equal expected

Expand Down