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

Update utilities.jl #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

millerjoey
Copy link

Fix to lagfill to address issue #133

fix to lagfill with TimeArray w/ greater than 1 horizontal dim
@codecov
Copy link

codecov bot commented Nov 9, 2021

Codecov Report

Merging #134 (d5b9bc6) into master (f0b6e22) will increase coverage by 0.28%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #134      +/-   ##
==========================================
+ Coverage   62.81%   63.10%   +0.28%     
==========================================
  Files           8        8              
  Lines         433      458      +25     
==========================================
+ Hits          272      289      +17     
- Misses        161      169       +8     
Impacted Files Coverage Δ
src/utilities.jl 81.69% <0.00%> (-10.12%) ⬇️
src/movingaverages.jl 100.00% <0.00%> (ø)
src/momentum.jl 36.19% <0.00%> (+0.79%) ⬆️
src/volume.jl 51.51% <0.00%> (+1.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f0b6e22...d5b9bc6. Read the comment docs.

@iblislin
Copy link
Member

iblislin commented Nov 9, 2021

diff --git a/src/utilities.jl b/src/utilities.jl
index 844d746..edc2fc0 100644
--- a/src/utilities.jl
+++ b/src/utilities.jl
@@ -92,19 +92,16 @@ function lagfill(ta::TimeArray, r1::Integer, fill::AbstractFloat)
   _lta_values = values(_lta)
   _lta_values[1:r1] .= fill
 
-  TimeArray(timestamp(ta), _lta_values, colnames(ta))
+  TimeArray(timestamp(ta), _lta_values, colnames(ta), unchecked = true)
 end
 
-function lagfill(ta::TimeArray, r1::Integer, fill::AbstractMatrix{T}) where T<:AbstractFloat
+function lagfill(ta::TimeArray, r1::Integer, fill::AbstractMatrix{<:AbstractFloat})
   @assert size(fill, 2) == size(ta, 2)
   _lta = lag(ta, r1, padding = true)
   _lta_values = values(_lta)
+  _lta_values[1:r1, :] .= fill
 
-  for i in 1:r1
-    _lta_values[i, :] = fill
-  end
-
-  TimeArray(timestamp(ta), _lta_values, colnames(ta))
+  TimeArray(timestamp(ta), _lta_values, colnames(ta), unchecked = true)
 end
 
 _nanmean(x) = mean(filter(!isnan, x))

@iblislin
Copy link
Member

iblislin commented Nov 9, 2021

And maybe we need to fix the colname of dpo

diff --git a/src/momentum.jl b/src/momentum.jl
index d73f151..a42f931 100644
--- a/src/momentum.jl
+++ b/src/momentum.jl
@@ -349,7 +349,7 @@ function dpo(ta::TimeArray, n::Integer = 14)
   lagPeriod = Int(floor(0.5*n) + 1)
   _lagc = lagfill(ta, lagPeriod, nanmean(values(ta)))
 
-  dpo = rename(_lagc .- moving(nanmean, ta, n), [:dpo])
+  dpo = rename!(_lagc .- moving(nanmean, ta, n), gen_colnames(colnames(ta), [:dpo]))
 end
 
 """

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.

2 participants