Skip to content

Commit

Permalink
Merge pull request #40 from drizk1/interp_sep
Browse files Browse the repository at this point in the history
  • Loading branch information
Karandeep Singh authored Sep 11, 2023
2 parents d6d97fd + 2f55ddc commit 8311b34
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# TidierData.jl updates

## v0.12.1 - 2023-09-11
- Fixes bug in `@separate()` so that the value of `into` supports interpolation.

## v0.12.0 - 2023-09-10
- Fixes `!!` interpolation so that it works using normal Julia scoping rules. It no longer uses `Main.eval()` in the implementation. The way interpolation works contains some breaking changes, and the documentation has been updated accordingly.
- Fixes name conflict with `Cleaner.rename()` and `DataFrames.rename()`
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TidierData"
uuid = "fe2206b3-d496-4ee9-a338-6a095c4ece80"
authors = ["Karandeep Singh"]
version = "0.12.0"
version = "0.12.1"

[deps]
Chain = "8be319e6-bccf-4806-a6f7-6fae938471bc"
Expand Down
6 changes: 6 additions & 0 deletions docs/examples/UserGuide/sep_unite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ df = DataFrame(a = ["1-1", "2-2", "3-3-3"]);
@separate(a, (b, c, d), "-")
end

# The into columns can also be designated as follows

new_names = ["x$(i)" for i in 1:3]; # or new_names = ["b", "c", "d"], or new_names = [:b, :c, :d]

@separate(df, a, !!new_names, "-")

# The `@unite` macro brings together multiple columns into one, separate the characters by a user specified delimiter

# ## Here, the `@unite` macro combines the "b", "c", and "d" columns columns into a single new "new_col" column using the "/" delimiter
Expand Down
27 changes: 18 additions & 9 deletions src/separate_unite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ end
$docstring_separate
"""
macro separate(df, from, into, sep)
from = QuoteNode(from)

if @capture(into, (args__,))
elseif @capture(into, [args__])
from_quoted = QuoteNode(from)

interpolated_into, _, _ = parse_interpolation(into)

if @capture(interpolated_into, (args__,)) || @capture(interpolated_into, [args__])
args = QuoteNode.(args)
into_expr = :[$(args...)]
else
into_expr = quote
if typeof($interpolated_into) <: Vector{String}
Symbol.($interpolated_into)
else
$interpolated_into
end
end
end

args = QuoteNode.(args)

var_expr = quote
separate($(esc(df)), $from, [$(args...)], $sep)

return quote
separate($(esc(df)), $(from_quoted), $(into_expr), $(esc(sep)))
end
end

Expand Down

2 comments on commit 8311b34

@kdpsingh
Copy link
Member

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/91212

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.1 -m "<description of version>" 8311b34db7ad2acc2d4547dd145de5e3f7b99f6d
git push origin v0.12.1

Please sign in to comment.