-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Negative start/stop/step in sile_read_multiple #578
Conversation
A major step with the last commit is the proposal to completely remove the For example:
|
src/sisl/io/xyz.py
Outdated
@@ -100,10 +100,10 @@ def _r_geometry_skip(self, *args, **kwargs): | |||
return na | |||
|
|||
@sile_fh_open() | |||
@sile_read_multiple(skip_call=_r_geometry_skip, postprocess=GeometryCollection) | |||
@sile_read_multiple(stop=1, skip_call=_r_geometry_skip, postprocess=GeometryCollection) |
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.
It would somehow be cleaner if the default was always to return everything, unless the user provides some selection with start/stop/step
.
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.
Yeah, probably that would be wisest... But this depends on the discussion above.
e42ce77
to
283813d
Compare
e53e8b8
to
e6cd106
Compare
Codecov Report
@@ Coverage Diff @@
## main #578 +/- ##
==========================================
+ Coverage 87.30% 87.32% +0.01%
==========================================
Files 374 374
Lines 47506 47496 -10
==========================================
Hits 41474 41474
+ Misses 6032 6022 -10
|
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 largely agree on everything, just some minor comments.
It would be great if @pfebrer could have a word here, he was interested in some MD functionality. It is a bit hard this one, since some file-formats are generically used for single geometries (xyz) while others are primarily MD files (ANI). It would feel weird for end-users that xyz
-files returns a GeometryCollection. But I think the current approach of returning the raw output could be annoying for those doing stuff on the fly.
We could accept it, but then it needs clear documentation.
src/sisl/io/xyz.py
Outdated
@@ -100,10 +100,10 @@ def _r_geometry_skip(self, *args, **kwargs): | |||
return na | |||
|
|||
@sile_fh_open() | |||
@sile_read_multiple(skip_call=_r_geometry_skip, postprocess=GeometryCollection) | |||
@sile_read_multiple(stop=1, skip_call=_r_geometry_skip, postprocess=GeometryCollection) |
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.
Yeah, probably that would be wisest... But this depends on the discussion above.
Signed-off-by: Nick Papior <nickpapior@gmail.com>
aa529a1
to
25b3f72
Compare
As I said when we discussed these things, the generic But I agree with all the points of this PR, I think the best way to go is to mimic python slice functionality since it will feel more natural for users and also you can use the python slicing syntax as syntactic sugar if it makes sense at some point. |
So I would try to make arguments mean exactly the same and have exactly the same defaults as As you discuss, this might be an issue because for some files it feels natural to read only one geometry, so the default should be sile = sisl.get_sile("file.xyz")
# Read the first geometry (or wherever the file handle is at)
sile.read_geometry()
# Reads a slice of geometries by first creating the iterator and then calling it.
sile.read_geometry[20:2:-1]()
# or
sile.read_geometry.multi(20, 2, -1)()
# In fact, you could use it as an iterator, which feels more natural than passing some `wrap` argument
reader = sile.read_geometry[20:2:-1]
for i, geom in reader:
... To me it feels natural and it would avoid these problems of "arbitrary" defaults for each sile. |
@pfebrer , thanks for your inputs. For |
Hmm in fact I found it confusing at the beggining that there was a Since it's not very well defined, I don't see it as a big problem to require the user to ask explicitly for something. I.e. By the way, |
I think @pfebrer is on to something here. I like both the slicing approach and the
|
I think the convention for returning single elements should be the last, for all methods. Then there will be no confusion. |
I think it would be enough if you can use the
But then you can't do what you usually suggest: with sile as open_sile:
for i in range(3):
open_sile.read_geometry() By the way I was using the word "slicing" but using |
Ah, true, so actually it should default to only the first one!
|
I think this highlights a need for different defaults for different |
True... But this is complicated for end-users... Hmm... We need to think carefully about the impacts in this regard. |
The simplest seem to be defaulting to read all entries (ie In the example by @pfebrer , one could do with sile as open_sile:
for i in range(3):
open_sile.read_geometry(step=0) |
Otherwise the defaults would depend on whether the file is open or not? |
Now I've implemented |
In my opinion, It seems clean and clear enough for me to specify the iterator externally (slicing, |
I think @pfebrer is on to something simple and effective. I'll have a look at this, as it is vital to get this in ASAP for API stability |
I have a somewhat working solution, see in the open("/tmp/test.file", 'w').write("""1
C 0.00000000 0.00000000 0.00000000
2
C 0.00000000 0.00000000 0.00000000
C 1.000000 0.00000000 0.00000000
3
C 0.00000000 0.00000000 0.00000000
C 1.000000 0.00000000 0.00000000
C 2.00000 0.00000000 0.00000000
""")
from sisl.io import xyzSile
sile = xyzSile("/tmp/test.file")
print(sile.read_geometry(), help(sile.read_geometry))
print(sile.read_geometry[0](), help(sile.read_geometry[0]))
print(sile.read_geometry[1]())
print(sile.read_geometry[1:]()) It isn't complete, but just to get an idea? |
I think the After all, this is how functions turn into methods so there's nothing very strange going on. Unless you can modify the |
By the way, what is the reason behind the name |
Lets continue the discussion in #584. Perhaps this MR should be closed, and then focus should be on the other branch? |
Here an attempt to handle negative
start/stop/step
insile_read_multiple
as discussed in #577 . If one specifies onlystart=-1
one now gets the last entry.If a negative
start/stop/step
is provided, the code reads all entries and returnsslice(start, stop, step)
.NB I am unsure if all corner cases are appropriately handled.