Skip to content

Commit

Permalink
Merge pull request #24 from mrufsvold/docstring-bug-fix
Browse files Browse the repository at this point in the history
clean up docstrings
  • Loading branch information
mrufsvold committed Jun 6, 2023
2 parents da2666e + 9312a1d commit 5f54adf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 0 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ tbl |> rows |> first

## API
```@docs
ExpandNestedData.expand(::Any)
ExpandNestedData.expand(::Any, ::Vector{ExpandNestedData.ColumnDefinition})
ExpandNestedData.ColumnDefinition(::Any;)
```
27 changes: 19 additions & 8 deletions src/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ using DataStructures: Stack
Expand a nested data structure into a Tables
Args:
## Args:
* data::Any - The nested data to unpack
* column::Vector{ColumnDefinition} - A list of paths to follow in `data`, ignoring other branches. Optional. Default: `nothing`.
* lazy_columns::Bool - If true, return columns using a lazy iterator. If false, `collect` into regular vectors before returning. Default: `true` (don't collect).
* pool_arrays::Bool - If true, use pool arrays to `collect` the columns. Default: `false`.
* column_names::Dict{Tuple, Symbol} - A lookup to replace column names in the final result with any other symbol
* column_style::Symbol - Choose returned column style from `:nested` or `:flat`. If nested, `column_names` are ignored and a TypedTables.Table is returned in which the columns are nested in the same structure as the source data. Default: `:flat`
* name_join_pattern::String - A pattern to put between the keys when joining the path into a column name. Default: `"_"`.
* column_defs::Vector{ColumnDefinition} - A list of paths to follow in `data`, ignoring other branches. Optional. Default: `nothing`.
## Kwargs:
* `lazy_columns::Bool` - If true, return columns using a lazy iterator. If false, `collect` into regular vectors before returning. Default: `true` (don't collect).
* `pool_arrays::Bool` - If true, use pool arrays to `collect` the columns. Default: `false`.
* `column_names::Dict{Tuple, Symbol}` - A lookup to replace column names in the final result with any other symbol
* `column_style::Symbol` - Choose returned column style from `:nested` or `:flat`. If nested, `column_names` are ignored
and a TypedTables.Table is returned in which the columns are nested in the same structure as the source data. Default: `:flat`
* `name_join_pattern::String` - A pattern to put between the keys when joining the path into a column name. Default: `"_"`.
## Returns
`::NamedTuple`
"""
function expand(data, column_definitions=nothing;
default_value = missing,
Expand All @@ -36,7 +40,14 @@ function expand(data, column_definitions=nothing;
construct_column_definitions(columns, column_names, pool_arrays, name_join_pattern) :
column_definitions

return ExpandedTable(columns, final_column_defs; lazy_columns = lazy_columns, pool_arrays = pool_arrays, column_style = typed_column_style, name_join_pattern=name_join_pattern)
expanded_table = ExpandedTable(columns, final_column_defs; lazy_columns = lazy_columns, pool_arrays = pool_arrays, column_style = typed_column_style, name_join_pattern=name_join_pattern)

final_table = if typed_column_style == flat_columns
as_flat_table(expanded_table)
elseif typed_column_style == nested_columns
as_nested_table(expanded_table)
end
return final_table
end

"""Wrap an object in the correct UnpackStep"""
Expand Down
6 changes: 3 additions & 3 deletions src/ExpandTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ pool_arrays(c::ColumnDefinition) = c.pool_arrays
## Returns
`::ColumnDefinition`
"""
function ColumnDefinition(field_path; kwargs...)
return ColumnDefinition(tuple(field_path...); kwargs...)
end
function ColumnDefinition(field_path::T; column_name=nothing, default_value=missing, pool_arrays=false, name_join_pattern::String = "_") where {T <: Tuple}
if column_name isa Nothing
path = last(field_path) == :unnamed ? field_path[1:end-1] : field_path
column_name = join_names(path, name_join_pattern)
end
ColumnDefinition(field_path, column_name, default_value, pool_arrays)
end
function ColumnDefinition(field_path; kwargs...)
return ColumnDefinition(tuple(field_path...); kwargs...)
end
function ColumnDefinition(field_path, column_names::Dict; pool_arrays::Bool, name_join_pattern = "_")
column_name = field_path in keys(column_names) ? column_names[field_path] : nothing
ColumnDefinition(field_path; column_name=column_name, pool_arrays=pool_arrays, name_join_pattern = name_join_pattern)
Expand Down
6 changes: 0 additions & 6 deletions src/ExpandedTable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ function ExpandedTable(columns::Dict{K, T}, column_defs::Vector{ColumnDefinition
for def in column_defs
)
expanded_table = ExpandedTable(col_lookup, column_tuple)

if column_style == flat_columns
return as_flat_table(expanded_table)
elseif column_style == nested_columns
return as_nested_table(expanded_table)
end
end

"""Build a nested NamedTuple of TypedTables from the columns following the same nesting structure
Expand Down

4 comments on commit 5f54adf

@mrufsvold
Copy link
Owner Author

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.

Error while trying to register: "Tag with name v1.0.0 already exists and points to a different commit"

@mrufsvold
Copy link
Owner Author

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/85025

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 v1.0.0 -m "<description of version>" 5f54adfef6e115dfc3d47e9f036a3760d8b74f49
git push origin v1.0.0

Please sign in to comment.