Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate varm and stdm #736

Merged
merged 2 commits into from
Nov 26, 2021
Merged

Deprecate varm and stdm #736

merged 2 commits into from
Nov 26, 2021

Conversation

nalimilan
Copy link
Member

varm and stdm are redundant with var(..., mean=m) and std(..., mean=m). Moreover, their status is not clear: they are technically exported by Statistics (but not by StatsBase itself), but their docstrings are not included in the manual. They were only tested indirectly, so add tests to ensure deprecations work.

The status of varm! is even weirder as it's imported from Statistics, but Statistics does not export it, and it has no docstrings. Keep a deprecation just in case.

`varm` and `stdm` are redundant with `var(..., mean=m)` and `std(..., mean=m)`.
Moreover, their status is not clear: they are technically exported by Statistics
(but not by StatsBase itself), but their docstrings are not included in the manual.
They were only tested indirectly, so add tests to ensure deprecations work.

The status of `varm!` is even weirder as it's imported from Statistics, but
Statistics does not export it, and it has no docstrings. Keep a deprecation
just in case.
@@ -39,3 +39,10 @@ end
### Deprecated September 2019
@deprecate sum(A::AbstractArray, w::AbstractWeights, dims::Int) sum(A, w, dims=dims)
@deprecate values(wv::AbstractWeights) convert(Vector, wv)

### Deprecated November 2021
@deprecate stdm(x::RealArray, w::AbstractWeights, m::Real; corrected::DepBool=nothing) std(x, w, mean=m, corrected=corrected) false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we disable export? This is breaking I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because it's not exported currently. We still overload the function defined in Statistics though to it can be used after using Statistics.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - OK. I mixed it up with the fact that Statistics exports it.

@@ -43,30 +23,22 @@ function var(v::RealArray, w::AbstractWeights; mean=nothing,
corrected = depcheck(:var, :corrected, corrected)

if mean == nothing
varm(v, w, Statistics.mean(v, w); corrected=corrected)
_moment2(v, w, Statistics.mean(v, w); corrected=corrected)
Copy link
Contributor

@bkamins bkamins Nov 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not var with kwarg? same below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're already in var. Calling ourselves with the computed mean would work but do you think it would really be cleaner?

(I'd like to deprecate _moment2 and similar functions at some point to simplify the API and implementation...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

corrected=corrected)
elseif mean == nothing
varm!(R, A, w, Statistics.mean(A, w, dims=dims), dims; corrected=corrected)
mean = Base.reducedim_initarray(A, dims, 0, eltype(R))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not tested. Also the same as above - why is it better than just calling the default replacement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out it's not tested on master already. This is an undocumented feature of var (which calls var!). I wish it wasn't allowed, but I guess we have keep supporting it now (and add tests for it)...

test/moments.jl Outdated
@@ -20,11 +20,13 @@ w = [3.84, 2.70, 8.29, 8.91, 9.71, 0.0]
@testset "Variance" begin
@test var(x, wv; corrected=false) ≈ expected_var
@test var(x, wv; mean=m, corrected=false) ≈ expected_var
@test varm(x, wv, m; corrected=false) ≈ expected_var
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should make the code alignment consistent everywhere?

@andreasnoack andreasnoack merged commit 89137fc into master Nov 26, 2021
@andreasnoack andreasnoack deleted the nl/depr branch November 26, 2021 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants