Created
January 25, 2020 23:37
-
-
Save dgkf/19026366df65904536cdbf91fabbd580 to your computer and use it in GitHub Desktop.
Itemized DataFrames.jl exports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using DataFrames, CSV | |
| df_exports = DataFrame(name = names(DataFrames)) | |
| # pull all objects from DataFrames namespace | |
| df_exports[:,:obj] .= map(eachrow(df_exports)) do row | |
| getfield(DataFrames, row.name) | |
| end | |
| # get object types | |
| df_exports[:,:type] .= map(df_exports.obj) do obj | |
| if obj isa Function; Function | |
| elseif typeof(obj) isa DataType; DataType | |
| else; typeof(obj) | |
| end | |
| end | |
| # for each function, check if it extends a Base function | |
| df_exports[:,:is_base] .= map(eachrow(df_exports)) do row | |
| row.obj isa Function && any([m.module == Base for m=methods(row.obj)]) | |
| end | |
| # for each Base function, create list of methods implemented and expand df | |
| base_extensions = map(eachrow(df_exports)) do row | |
| if row.is_base; [m for m=methods(row.obj) if m.module == DataFrames] | |
| else; missing | |
| end | |
| end | |
| base_extension_n = vcat(map(enumerate(base_extensions)) do (i, e) | |
| if e isa Missing; return(i) | |
| else; return(repeat([i], length(e))) | |
| end | |
| end...) | |
| df_exports = df_exports[base_extension_n,:] | |
| df_exports[:,:base_extension] .= vcat(base_extensions...) | |
| # expand base extension into file and line | |
| df_exports[:,:file] .= map(eachrow(df_exports)) do row | |
| if row.base_extension isa Missing; missing | |
| elseif (m = match(r"src/.*", string(row.base_extension.file))) isa Nothing; missing | |
| else; m.match | |
| end | |
| end | |
| # expand base extension data into line | |
| df_exports[:,:line] .= map(eachrow(df_exports)) do row | |
| row.base_extension isa Missing ? missing : row.base_extension.line | |
| end | |
| # for each base method, gather array of positional arguments | |
| df_exports[:,:signature] .= map(eachrow(df_exports)) do row | |
| if row.base_extension isa Method | |
| sig = row.base_extension.sig | |
| sig = sig isa UnionAll ? Base.unwrap_unionall(sig) : sig | |
| [t for (i,t)=enumerate(sig.parameters) if i>1] | |
| else | |
| missing | |
| end | |
| end | |
| # for each base method, gather array of keyword arguments | |
| df_exports[:,:kwargs] .= map(eachrow(df_exports)) do row | |
| if row.base_extension isa Method | |
| kws = try; typeof(row.obj).name.mt.kwsorter; catch; nothing; end | |
| keywords = Base.kwarg_decl(row.base_extension, typeof(kws)) | |
| length(keywords) > 0 ? keywords : missing | |
| else | |
| missing | |
| end | |
| end | |
| # remove objects from dataframe for writing out to csv | |
| df_exports = df_exports[:, .! in.(names(df_exports), [[:obj, :base_extension]])] | |
| CSV.write("dataframes_exports.csv", df_exports) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment