Skip to content

Commit eaa1416

Browse files
asinghvi17nalimilanclaude
committed
Address PR review feedback for v1.0.0 release
- Fix docstring conventions: "Returns" -> "Return", "Invoked" -> "Obtained" - Capitalize "Markdown" consistently in documentation - Move DataFrame constraint info from signature comment into docstring body - Remove unnecessary DataFrames. prefixes (use metadata!, metadatakeys, metadata directly) - Replace unexported note with @public declaration for description and packages - Add SciMLPublic.jl dependency for @public macro - Throw error instead of warning when DataFrame lacks RDatasets metadata - Add `default` keyword argument to description(df) for graceful fallback - Bump version to 1.0.0 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Milan Bouchet-Valat <[email protected]> Co-Authored-By: Claude <[email protected]>
1 parent 30ad0b0 commit eaa1416

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "RDatasets"
22
uuid = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
3-
version = "0.8.0"
3+
version = "1.0.0"
44

55
[deps]
66
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
@@ -11,6 +11,7 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
1111
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1212
RData = "df47a6cb-8c03-5eed-afd8-b6050d6c41da"
1313
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
14+
SciMLPublic = "431bcebd-1456-4ced-9d72-93c2757fff0b"
1415

1516
[compat]
1617
CSV = "0.5, 0.6, 0.7, 0.8, 0.9, 0.10"
@@ -19,6 +20,7 @@ DataFrames = "0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 1"
1920
FileIO = "1"
2021
RData = "0.5, 0.6, 0.7, 0.8, 1"
2122
Reexport = "0.2, 1.0"
23+
SciMLPublic = "1"
2224
julia = "1"
2325

2426
[extras]

src/RDatasets.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ module RDatasets
44
end
55

66
import Markdown
7+
import SciMLPublic: @public
78
using Reexport, RData, CSV, CodecZlib
89
@reexport using DataFrames
910

1011
export dataset
12+
@public description, packages
1113

1214
global __packages = nothing
1315
global __datasets = nothing

src/dataset.jl

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ function dataset(package_name::AbstractString, dataset_name::AbstractString)
2525
error("Unable to locate dataset file $rdaname or $csvname")
2626
end
2727
# Finally, inject metadata into the dataframe to indicate origin:
28-
DataFrames.metadata!(dataset, "RDatasets.jl", (string(package_name), string(dataset_name)))
28+
metadata!(dataset, "RDatasets.jl", (string(package_name), string(dataset_name)))
2929
return dataset
3030
end
3131

3232

3333
"""
3434
RDatasets.description(package_name::AbstractString, dataset_name::AbstractString)
35-
RDatasets.description(df::DataFrame) # only call this on dataframes from RDatasets!
35+
RDatasets.description(df::AbstractDataFrame; default=nothing)
3636
37-
Returns an `RDatasetDescription` object containing the description of the dataset.
37+
Return an `RDatasetDescription` object containing the description of the dataset.
3838
3939
Invoke this function in exactly the same way you would invoke `dataset` to get the dataset itself.
4040
41-
This object prints well in the REPL, and can also be shown as markdown or HTML.
41+
This object prints well in the REPL, and can also be shown as Markdown or HTML.
4242
43-
!!! note Unexported
44-
This function is left deliberately unexported, since the name is pretty common.
43+
When passing a `DataFrame`, it must have been obtained from `RDatasets.dataset`. If the DataFrame
44+
does not have the required metadata, an error is thrown unless a `default` value is provided,
45+
in which case that value is returned instead.
4546
"""
4647
function description(package_name::AbstractString, dataset_name::AbstractString)
4748
doc_html_file = joinpath(@__DIR__, "..", "doc", package_name, "$dataset_name.html")
@@ -53,15 +54,15 @@ function description(package_name::AbstractString, dataset_name::AbstractString)
5354
end
5455

5556
# This is a convenience function to get the description of a dataset from a DataFrame.
56-
# Since we set metadata on the DataFrame, we can use this to get the description,
57-
# if it exists.
58-
function description(df::AbstractDataFrame)
59-
if "RDatasets.jl" in DataFrames.metadatakeys(df)
60-
package_name, dataset_name = DataFrames.metadata(df, "RDatasets.jl")
57+
# Since we set metadata on the DataFrame, we can use this to get the description.
58+
function description(df::AbstractDataFrame; default=nothing)
59+
if "RDatasets.jl" in metadatakeys(df)
60+
package_name, dataset_name = metadata(df, "RDatasets.jl")
6161
return description(package_name, dataset_name)
62+
elseif default !== nothing
63+
return default
6264
else
63-
@warn "No metadata indicating dataset origin found. Returning default description."
64-
return RDatasetDescription("No description available.")
65+
throw(ArgumentError("DataFrame does not have RDatasets.jl metadata. Use a DataFrame obtained from `RDatasets.dataset`, or provide a `default` value."))
6566
end
6667
end
6768

@@ -71,9 +72,9 @@ end
7172
A type to hold the content of a dataset description.
7273
7374
The main purpose of its existence is to provide a way to display the content
74-
differently in HTML and markdown contexts.
75+
differently in HTML and Markdown contexts.
7576
76-
Invoked through [`RDatasets.description`](@ref).
77+
Obtained through [`RDatasets.description`](@ref).
7778
"""
7879
struct RDatasetDescription
7980
content::String

0 commit comments

Comments
 (0)