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

LASFile.write raises exception if the ~Other section has been removed #435

Open
kinverarity1 opened this issue Apr 9, 2021 · 0 comments
Labels
bug las-writer-code A bug or enhancement relating to code which creates LAS files

Comments

@kinverarity1
Copy link
Owner

Describe the bug
If the ~Other section is removed from a LASFile object, when the LASFile is written, an exception is raised.

To Reproduce
See #417 for the setup code.

Removing an empty ~Other section from the LASFile header throws a KeyError exception when writing to file:

las.header.pop('Other')
las.write(testfn)
>>>>
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-17-169d1c4eb1e4> in <module>
----> 1 las.write(testfn)

~/venv/lib/python3.8/site-packages/lasio-0.28-py3.8.egg/lasio/las.py in write(self, file_ref, **kwargs)
    384             opened_file = True
    385             file_ref = open(file_ref, "w")
--> 386         writer.write(self, file_ref, **kwargs)
    387         if opened_file:
    388             file_ref.close()

~/venv/lib/python3.8/site-packages/lasio-0.28-py3.8.egg/lasio/writer.py in write(las, file_object, version, wrap, STRT, STOP, STEP, fmt, column_fmt, len_numeric_field, data_width, header_width)
    186     logger.debug("LASFile.write Other section")
    187     lines.append("~Other ".ljust(header_width, "-"))
--> 188     lines += las.other.splitlines()
    189 
    190     logger.debug("LASFile.write ASCII section")

~/venv/lib/python3.8/site-packages/lasio-0.28-py3.8.egg/lasio/las.py in other(self)
    637 
    638         """
--> 639         return self.sections["Other"]
    640 
    641     @other.setter

KeyError: 'Other'

Expected behavior
Attempts to remove the ~Other section from a LASFile should raise a warning, and an empty Other section should be retained (as in the default LASFile object), so that no exception is raised on an attempt to serialize or write the LASFile.

Software versions (please complete the following information):

Additional context
This issue was created from #417

@kinverarity1 kinverarity1 added the las-writer-code A bug or enhancement relating to code which creates LAS files label Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug las-writer-code A bug or enhancement relating to code which creates LAS files
Projects
None yet
Development

No branches or pull requests

1 participant