Skip to content

Commit

Permalink
v0.4 - add Aqua, fix tests, limit Julia compat
Browse files Browse the repository at this point in the history
  • Loading branch information
nilshg committed Jan 17, 2024
1 parent 996e16d commit 016cc28
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/Manifest.toml
.vscode/settings.json
test/Manifest.toml
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TreatmentPanels"
uuid = "7885c543-3ac4-48a3-abed-7a36d7ddb69f"
authors = ["Nils <[email protected]> and contributors"]
version = "0.3.0"
version = "0.4.0"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand All @@ -11,9 +11,11 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"

[compat]
DataFrames = "1"
Dates = "1"
RecipesBase = "1"
Parameters = "0.12"
julia = "1"
Test = "1"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![CI](https://github.com/nilshg/TreatmentPanels.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/nilshg/TreatmentPanels.jl/actions/workflows/ci.yml)
[![Aqua QA](https://raw.githubusercontent.com/JuliaTesting/Aqua.jl/master/badge.svg)](https://github.com/JuliaTesting/Aqua.jl)


# TreatmentPanels

Expand All @@ -17,7 +19,7 @@ julia> Pkg.add("TreatmentPanels")
or in the Pkg REPL

```
(@v1.7) add TreatmentPanels
(@v1.10) add TreatmentPanels
```

## Quickstart
Expand Down
23 changes: 21 additions & 2 deletions src/TreatmentPanel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function treated_ids(x::BalancedPanel{SingleUnitTreatment{T}}) where T
end

function treated_ids(x::BalancedPanel{MultiUnitTreatment{T}}) where T
findall(>(0), vec(sum(Y, dims = 2)))
any.(eachrow(x.W))
end

"""
Expand All @@ -197,17 +197,27 @@ function treated_labels(x::BalancedPanel{SingleUnitTreatment{T}}) where T
x.is[treated_ids(x)]
end

function treated_labels(x::BalancedPanel{MultiUnitTreatment{Simultaneous{Continuous}}})
x.is[treated_ids(x)]
end

"""
first_treated_period_ids(x <: BalancedPanel)
Returns the indices of the first treated period for each treated units, that is, a Vector{Int}
of length Nₜᵣ, where each element is the index of the first 1 in the row of treatment matrix W
corresonding to the treatment unit.
For a single treated unit, returns only the index of the first treated period. For multiple
"""
function first_treated_period_ids(x::BalancedPanel{SingleUnitTreatment{T}}) where T
findfirst(vec(x.W[treated_ids(x), :]))
end

function first_treated_period_ids(x::BalancedPanel{MultiUnitTreatment{T}}) where T
[x for x findfirst.(eachrow(x.W)) if !isnothing(x)]
end

"""
first_treated_period_labels(x <: BalancedPanel)
Expand All @@ -227,6 +237,11 @@ function length_T₀(x::BalancedPanel{SingleUnitTreatment{Continuous}})
first_treated_period_ids(x) - 1
end

function length_T₀(x::BalancedPanel{MultiUnitTreatment{Simultaneous{Continuous}}})
first_treated_period_ids(x) .- 1
end


"""
length_T₁(x <: BalancedPanel)
Expand All @@ -236,6 +251,9 @@ function length_T₁(x::BalancedPanel{SingleUnitTreatment{Continuous}})
size(x.Y, 2) .- first_treated_period_ids(x) + 1
end

function length_T₁(x::BalancedPanel{MultiUnitTreatment{Simultaneous{Continuous}}})
size(x.Y[treated_ids(x), :], 2) .- first_treated_period_ids(x) .+ 1
end

"""
get_y₁₀(x <: BalancedPanel)
Expand All @@ -247,6 +265,7 @@ function get_y₁₀(x::BalancedPanel{SingleUnitTreatment{Continuous}})
x.Y[treated_ids(x), 1:first_treated_period_ids(x)-1]
end


"""
get_y₁₁(x <: BalancedPanel)
Expand Down Expand Up @@ -340,7 +359,7 @@ end
# Fallback method - if the length of treatment assignment is one use single treatment method above
function BalancedPanel(df::DataFrame, treatment_assignment;
id_var = nothing, t_var = nothing, outcome_var = nothing,
sort_inplace = false) where NType where TType
sort_inplace = false)

if length(treatment_assignment) == 1
return BalancedPanel(df, only(treatment_assignment); id_var = id_var, t_var = t_var,
Expand Down
5 changes: 3 additions & 2 deletions src/TreatmentPanels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ include("show_and_plot.jl")

# Export main types
export TreatmentPanel
export BalancedPanel, UnbalancedPanel
export BalancedPanel
# export UnbalancedPanel - Not yet implemented

# Export treatment description types
export UnitTreatmentType
export TreatmentType
export SingleUnitTreatment, MultiUnitTreatment
export TreatmentTimingType
export Staggered, Simultaneous
Expand Down
12 changes: 12 additions & 0 deletions test/Aqua.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Aqua

@testset "Aqua.jl" begin
Aqua.test_ambiguities(TreatmentPanels)
Aqua.test_unbound_args(TreatmentPanels)
Aqua.test_undefined_exports(TreatmentPanels)
Aqua.test_project_extras(TreatmentPanels)
Aqua.test_stale_deps(TreatmentPanels)
Aqua.test_deps_compat(TreatmentPanels)
Aqua.test_piracies(TreatmentPanels)
Aqua.test_persistent_tasks(TreatmentPanels)
end
14 changes: 14 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.8"
DataFrames = "1"
Dates = "1"
Documenter = "1"
Test = "1"

2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using TreatmentPanels
using Test
using DataFrames, Dates

include("Aqua.jl")

@testset "Input tests" begin
test_df = DataFrame(id = ["a", "a", "b", "b"], period = [1, 2, 1, 2], value = 1.0:4.0)

Expand Down

0 comments on commit 016cc28

Please sign in to comment.