Skip to content

Commit

Permalink
adds Aqua checks; fixes some issues highlighted by Aqua
Browse files Browse the repository at this point in the history
  • Loading branch information
sadit committed Aug 1, 2022
1 parent 0a0f373 commit c87a7fa
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 40 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,3 @@ jobs:
- uses: codecov/codecov-action@v1
with:
file: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
julia --project=docs -e '
using Documenter: doctest
using KNearestCenters
doctest(KNearestCenters)'
- run: julia --project=docs docs/make.jl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
24 changes: 24 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Documentation

on:
push:
branches:
- main
tags: '*'
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # If authenticating with SSH deploy key
run: julia --project=docs/ docs/make.jl
10 changes: 6 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ version = "0.7.2"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
KCenters = "5d8de97f-65f8-4dd6-a15b-0f89c36a43ce"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LossFunctions = "30fc2ffe-d236-52d8-8643-a9d8f7c094a7"
MLLabelUtils = "66a33bbf-0c2b-5fc8-a008-9da813334f0a"
MLUtils = "f1d291b0-491e-4a28-83b9-f70985020b54"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SearchModels = "0e966ebe-b704-4a65-8279-db954bfe5da0"
Expand All @@ -20,16 +17,21 @@ StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
Aqua = "0.5"
CategoricalArrays = "0.8, 0.9, 0.10"
KCenters = "0.7"
LossFunctions = "0.8"
MLUtils = "0.2.9"
SearchModels = "0.3"
SimilaritySearch = "0.8, 0.9"
StatsAPI = "1.4"
StatsBase = "0.32, 0.33"
julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "CSV"]
test = ["Aqua", "Test", "CSV"]
2 changes: 1 addition & 1 deletion src/KNearestCenters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SearchModels: combine, mutate
import StatsAPI: predict, fit
using MLUtils

export Knc, KncConfig, KncConfigSpace, KncProto, KncProtoConfig, KncProtoConfigSpace, KncPerClassConfigSpace, KncGlobalConfigSpace
export Knc, KncConfig, KncConfigSpace, KncProto, KncProtoConfig, KncProtoConfigSpace
export transform, predict, fit, categorical

include("scores.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/criterions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of KNearestCenters.jl

export size_criterion, sqrt_criterion, change_criterion, fun_criterion, log_criterion, epsilon_criterion, salesman_criterion
export size_criterion, sqrt_criterion, change_criterion, fun_criterion, epsilon_criterion, salesman_criterion


"""
Expand Down
11 changes: 4 additions & 7 deletions src/knn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,11 @@ function fit(::Type{KnnModel}, index::AbstractSearchIndex, labels::CategoricalAr
KnnModel(k, 1, KnnSingleLabelPrediction(imap), weight, index, meta_)
end

function fit(::Type{KnnModel}, examples, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel(), dist=L2Distance())
meta_, imap = onehotenc(labels)
if examples isa AbstractArray
db = MatrixDatabase(examples)
else
db = examples
end
fit(::Type{KnnModel}, examples::AbstractMatrix, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel(), dist=L2Distance()) =
fit(KnnModel, MatrixDatabase(examples), labels; k, weight, dist)

function fit(::Type{KnnModel}, db::AbstractDatabase, labels::CategoricalArray; k=3, weight=KnnUniformWeightKernel(), dist=L2Distance())
meta_, imap = onehotenc(labels)
index = ParallelExhaustiveSearch(; db, dist)
KnnModel(k, 1, KnnSingleLabelPrediction(imap), weight, index, meta_)
end
Expand Down
2 changes: 1 addition & 1 deletion src/knnopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function optimize!(
]
)
optimize!(model, klist, wlist) do
predict.(model, Xtest)
ypred = predict.(model, Xtest)
value(loss, ytest, ypred)
end
end
Expand Down
11 changes: 7 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# This file is a part of KCenters.jl

using Test
using KNearestCenters
using Test, KNearestCenters

using Aqua
Aqua.test_all(KNearestCenters, ambiguities=false)
Aqua.test_ambiguities([KNearestCenters, Core])

@testset "Scores" begin
@test accuracy_score([1,1,1,1,1], [1,1,1,1,1]) == 1.0
Expand All @@ -16,6 +19,6 @@ using KNearestCenters
@test f1_score([0,1,1,1,0,1], [0,1,1,1,1,1], weight=:macro) (2 * 0.5 / 1.5 + 2 * 0.8 / 1.8) / 2
end

#include("knc.jl")
include("knc.jl")
include("kncproto.jl")
#include("knn.jl")
include("knn.jl")

2 comments on commit c87a7fa

@sadit
Copy link
Owner Author

@sadit sadit commented on c87a7fa Aug 1, 2022

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

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.7.2 -m "<description of version>" c87a7fae58287b0cb5c3b45167ecbc67fe2f6c0d
git push origin v0.7.2

Please sign in to comment.