-
Notifications
You must be signed in to change notification settings - Fork 35
begin and end: Indexing Interface for TimestepArrays #695
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
Conversation
return length(v.data) | ||
end | ||
|
||
Base.lastindex(v::TimestepVector) = length(v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this line since it's a duplicate of the new method.
Codecov Report
@@ Coverage Diff @@
## master #695 +/- ##
==========================================
- Coverage 80.16% 79.73% -0.43%
==========================================
Files 38 38
Lines 2858 2877 +19
==========================================
+ Hits 2291 2294 +3
- Misses 567 583 +16
Continue to review full report at Codecov.
|
@lrennels the use case I ran into was in PAGE, where there are components that do v.varname[end] in the run_timestep function. This is currently causing the Int indexing deprecation warning, I think because our previous implementation of lastindex was to return an Int. So I think what you've implemented here (to return a TImestepIndex instead) is correct. I do think we should also get it working for when there are more than one dimension. So the ones you've marked as "todo" would be something like
I think that's what your suggesting, does that make sense? |
Yea, I was thinking of implementing that kind of logic in the leftover methods, but it seemed a little strange to return two different types from the same function but I guess fine since it's such a generic function and specific use case. I'd need to implement that logic too in the existing methods, because for example
if there are multiple dimensions, that the |
I think for now the use cases best to think about are taking the I can implement the methods above today though and we can merge those. |
@ckingdon95 ok it's ready! All tests do pass on |
This looks great! But it looks like at least the I think this is showing what's not covered in red: |
The axes function is required by some uses of begin, which I’m not testing right now because they trigger an error in some versions of Julia that don’t support begin (it was deprecated in v1.0.0). I can try to add a version check and check it in v1.4.0 at least. |
test/test_timesteparrays.jl
Outdated
@test eltype(x_vec) == eltype(y_vec) == eltype(y_vec) == eltype(y_mat) == eltype(time_dim_val) | ||
|
||
# begin syntax is depreacated v1.0.0 - v1.3.0 | ||
if(VERSION > v"1.3.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ckingdon95 This doesn't seem to be helping, might be because of how the file is parsed, but v1.2.0
and v1.3.0
catch an error in this block. I'll look into it.
@ckingdon95 I just can't get the parsing to work properly, so per the conversation yesterday I'm commenting out the tests for now and adding a TODO note so we can reenable them as soon as we don't support sub-v1.4.0 versions of Julia. I did double check that the tests are successful on my local machine, which is on v1.4.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests pass, hurray! @ckingdon95, can you also look over this, and then we merge?
This addresses PR #691
@ckingdon95 what was the use case you saw for
begin
andend
? I thinkbegin
for indexing got deprecated in Julia v1.0.0 (https://discourse.julialang.org/t/what-is-the-current-and-future-status-of-begin-keyword-in-indexing/13145) but came back by at leastv1.4.0
so I need to sort that out in testing. Regardless it's a little funky so I want to make sure I understand the case/needI implemented these:
Which so far allows us to index with syntax like
Some issues arise however, when we have a multidimensional array and of course only one dimension is time:
TimesteoIndex
if the begin or end is not actually in the.time
dimension. We could return different types depending on the dimension but that seems like a faux pasbegin
andend
generally only concern one dimension at a time iearr[TimestepIndex(3), 5:end]
? Going across dimensions seems odd?