[segyio] 332/376: Add negative indexing on segy.header
Jørgen Kvalsvik
jokva-guest at moszumanska.debian.org
Wed Sep 20 08:04:54 UTC 2017
This is an automated email from the git hooks/post-receive script.
jokva-guest pushed a commit to branch debian
in repository segyio.
commit 58dd5f03ef4c390700f1c04cc1fcf88e455eda48
Author: Jørgen Kvalsvik <jokva at statoil.com>
Date: Fri Aug 11 10:02:33 2017 +0200
Add negative indexing on segy.header
---
python/segyio/_field.py | 7 +++++--
python/test/segy.py | 9 +++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/python/segyio/_field.py b/python/segyio/_field.py
index 0024b13..02ac76f 100644
--- a/python/segyio/_field.py
+++ b/python/segyio/_field.py
@@ -90,8 +90,11 @@ class Field(object):
@classmethod
def trace(cls, buf, traceno, segy):
- if traceno >= segy.tracecount:
- raise IndexError("Trace number out of range: 0 <= %d < %d" % (traceno, segy.tracecount))
+ if traceno < 0:
+ traceno = segy.tracecount + traceno
+
+ if traceno >= segy.tracecount or traceno < 0:
+ raise IndexError("Header out of range: 0 <= %d < %d" % (traceno, segy.tracecount))
if buf is None:
buf = segyio._segyio.empty_traceheader()
diff --git a/python/test/segy.py b/python/test/segy.py
index 5bc7220..35b6a1e 100644
--- a/python/test/segy.py
+++ b/python/test/segy.py
@@ -471,6 +471,15 @@ class TestSegy(TestCase):
self.assertEqual(1, f.header[0][189])
self.assertEqual(1, f.header[1][TraceField.INLINE_3D])
self.assertEqual(1, f.header[1][segyio.su.iline])
+ self.assertEqual(5, f.header[-1][segyio.su.iline])
+ self.assertEqual(5, f.header[24][segyio.su.iline])
+ self.assertEqual(dict(f.header[-1]), dict(f.header[24]))
+
+ with self.assertRaises(IndexError):
+ f.header[30]
+
+ with self.assertRaises(IndexError):
+ f.header[-30]
with self.assertRaises(IndexError):
f.header[0][188] # between byte offsets
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/segyio.git
More information about the debian-science-commits
mailing list