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

Subsetting time axis with DateTime using Near(Date(...)) fails #589

Closed
felixcremer opened this issue Jan 10, 2024 · 1 comment · Fixed by #598
Closed

Subsetting time axis with DateTime using Near(Date(...)) fails #589

felixcremer opened this issue Jan 10, 2024 · 1 comment · Fixed by #598

Comments

@felixcremer
Copy link
Contributor

When I try to subset a time axis which has an DateTime element type with a Near(Date(something)) this fails and I would have expected that we could use either Date or DateTime at least in the Near selector.
I am not sure, what we can do about that.
I tried to reproduce this with an MWE but with the artificial time axis I constructed this works.

julia> winter = r1[Ti=Near(Date(1995, 4,1))]
ERROR: MethodError: no method matching -(::Date, ::DateTime)

Closest candidates are:
  -(::Date, ::Day)
   @ Dates ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:82
  -(::Date, ::Week)
   @ Dates ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:80
  -(::Date, ::Quarter)
   @ Dates ~/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/Dates/src/arithmetic.jl:76
  ...

Stacktrace:
  [1] near
    @ DimensionalData.Dimensions.LookupArrays ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/LookupArrays/selector.jl:265 [inlined]
  [2] near
    @ DimensionalData.Dimensions.LookupArrays ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/LookupArrays/selector.jl:241 [inlined]
  [3] selectindices
    @ DimensionalData.Dimensions.LookupArrays ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/LookupArrays/selector.jl:230 [inlined]
  [4] _dims2indices
    @ DimensionalData.Dimensions ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/Dimensions/indexing.jl:114 [inlined]
  [5] macro expansion
    @ DimensionalData.Dimensions ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/Dimensions/indexing.jl:56 [inlined]
  [6] _dims2indices
    @ DimensionalData.Dimensions ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/Dimensions/indexing.jl:56 [inlined]
  [7] dims2indices
    @ DimensionalData.Dimensions ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/Dimensions/indexing.jl:51 [inlined]
  [8] dims2indices
    @ DimensionalData.Dimensions ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/Dimensions/indexing.jl:34 [inlined]
  [9] view(::YAXArray{Union{…}, 3, DiskArrayTools.CFDiskArray{…}, Tuple{…}}; kw::@Kwargs{Ti::Near{…}})
    @ DimensionalData ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/array/indexing.jl:47
 [10] view
    @ ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/DimensionalData/src/array/indexing.jl:47 [inlined]
 [11] getindex(::YAXArray{Union{…}, 3, DiskArrayTools.CFDiskArray{…}, Tuple{…}}; kwargs::@Kwargs{Ti::Near{…}})
    @ YAXArrays.Cubes ~/Documents/NFDI4Earth/deliverables/D2.5_1-5_Overview_DC_tech/dev/YAXArrays/src/Cubes/Cubes.jl:483
 [12] top-level scope
    @ REPL[82]:1
Some type information was truncated. Use `show(err)` to see complete types.

julia> winter = r1[Ti=Near(DateTime(1995, 4,1))]
848×824 YAXArray{Union{Missing, Float32},2} with dimensions: 
  Dim{:rlon} Sampled{Float64} -28.4029998779297:0.0550011811599821:18.18300056457514 ForwardOrdered Regular Points,
  Dim{:rlat} Sampled{Float64} -23.4029998779297:0.0550012159753107:21.863000869751005 ForwardOrdered Regular Points
units: K
name: tas
Total size: 2.67 MB
@rafaqz
Copy link
Owner

rafaqz commented Jan 11, 2024

Yeah Date is pretty annoying, we would have to convert it to DateTime for that to work

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 a pull request may close this issue.

2 participants