Skip to content

Commit

Permalink
Fix tests (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
greimel authored Jun 28, 2023
1 parent cf3c68a commit 8d4dc17
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DINA"
uuid = "2e9d5fb1-712f-4dff-9379-c18f12b3746d"
authors = ["Fabian Greimel <[email protected]> and contributors"]
version = "0.2.0"
version = "0.2.1"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
2 changes: 1 addition & 1 deletion src/DINA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function aggregate_quantiles(var, byvar, ngroups, year; wgt, by_taxunit)
# Aggregate by group
agg_df = combine(
groupby(df, [:group_id, :age]),
([v, wgt] => ((x,w) -> mean(x, weights(w))) => v for v in var)..., wgt => sum => wgt
([v, wgt] => ((x,w) -> dot(x, w) / sum(w)) => v for v in var)..., wgt => sum => wgt
)

agg_df[!,:year] .= year
Expand Down
17 changes: 9 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ using TestItemRunner

@run_package_tests

@testitem "DINA.jl" begin
import CSV

@testitem "DINA.jl" begin
tbl = get_dina(1980)
@test tbl isa DINA.DataFrames.DataFrame

Expand All @@ -14,22 +12,25 @@ using TestItemRunner

df_1980 = aggregate_quantiles(var, :fiinc, 10, 1980; wgt = :dweght, by_taxunit = true)

df = dina_quantile_panel(var, :fiinc, 10, [1980;2007])
df = dina_quantile_panel(var, :fiinc, 10, [1962; 1980;2007])
sort!(df, [:year, :group_id, :age])
@test abs(df.fiinc[1] - (-175.761)) < 0.01
@test df isa DINA.DataFrames.DataFrame
@test size(df) == (60, 11)

@test size(df) == (80, 11)
end

@testitem "Income group panel" begin
using CSV: CSV

var = [:fiinc, :fninc, :ownermort, :ownerhome, :rentalmort, :rentalhome]

df = dina_quantile_panel(var, :fiinc, 10)
@test df isa DINA.DataFrames.DataFrame
@test size(df) == (1530, 11)

filename = joinpath(@__DIR__(), "dina-aggregated.csv")
sort!(df, [:year, :group_id, :age])
df |> CSV.write(filename)

@show filename

@show filename
end

2 comments on commit 8d4dc17

@greimel
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 register()

@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/86467

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.2.1 -m "<description of version>" 8d4dc17e05c0561044570a94af4258da21332a0d
git push origin v0.2.1

Please sign in to comment.