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

file like objects can be used to read and write tspair and slist #3372

Closed
wants to merge 4 commits into from

Conversation

raciner
Copy link

@raciner raciner commented Nov 16, 2023

Can now also read and write to file-like objects the same way as the mseed module. Using io.BytesIO comes in handy for example when you use obspy in a web server context. This way, it doesn't need to generate intermediate files on disk.

What does this PR do?

Please fill in

Why was it initiated? Any relevant Issues?

Please fill in (link relevant issues with "see #123456", mark issues that get resolved with "fixes #12345")

PR Checklist

  • Correct base branch selected? master for new features, maintenance_... for bug fixes
  • This PR is not directly related to an existing issue (which has no PR yet).
  • While the PR is still work-in-progress, the no_ci label can be added to skip CI builds
  • If the PR is making changes to documentation, docs pages can be built automatically.
    Just add the build_docs tag to this PR.
    Docs will be served at docs.obspy.org/pr/{branch_name} (do not use master branch).
    Please post a link to the relevant piece of documentation.
  • If all tests including network modules (e.g. clients.fdsn) should be tested for the PR,
    just add the test_network tag to this PR.
  • All tests still pass.
  • Any new features or fixed regressions are covered via new tests.
  • Any new or changed features are fully documented.
  • Significant changes have been added to CHANGELOG.txt .
  • First time contributors have added your name to CONTRIBUTORS.txt .
  • If the changes affect any plotting functions you have checked that the plots
    from all the CI builds look correct. Add the "upload_plots" tag so that plotting
    outputs are attached as artifacts.
  • New modules, add the module to CODEOWNERS with your github handle
  • Add the yellow ready for review label when you are ready for the PR to be reviewed.

Can now also read and write to file-like objects the same way as the mseed module.
@megies
Copy link
Member

megies commented Nov 22, 2023

Didn't look at details yet but 👍
One thing that is missing is, if a file like object gets passed in, we need to save and restore the position of the open file pointer in the _is_... method or file format auto-detection breaks as soon as it hit's these I/O plugins here, see last commits in #3370 for what I mean

Copy link
Member

@megies megies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some PEP8 issues (see reviewdog comments inline) and needs to save/restore file position

@megies megies added this to the 1.5.0 milestone Nov 22, 2023
@megies megies added the .io issues generally related to our read/write plugins label Nov 22, 2023
The code now passes all tests but one on my PC:
AssertionError: '185.[15 chars]00043\t185.0299988\t189.0399933\t194.0500031\t205.0599976' != '185.[15 chars]000430000001\t185.02999879999999\t189.03999329[28 chars]9976'
- 185.0099945	181.0200043	185.0299988	189.0399933	194.0500031	205.0599976
?            	           	          ^	          ^
+ 185.0099945	181.02000430000001	185.02999879999999	189.03999329999999	194.0500031	205.0599976
?            	           +++++++	          ^^^^^^^^	          ^^^^^^^^

This might be a shortcoming of the test.
@raciner
Copy link
Author

raciner commented Nov 27, 2023

The code now passes the unit test on my PC except for probable rounding issues

    self.assertEqual(
AssertionError: '185.[15 chars]00043\t185.0299988\t189.0399933\t194.0500031\t205.0599976' != '185.[15 chars]000430000001\t185.02999879999999\t189.03999329[28 chars]9976'
- 185.0099945	181.0200043	185.0299988	189.0399933	194.0500031	205.0599976
?            	           	          ^	          ^
+ 185.0099945	181.02000430000001	185.02999879999999	189.03999329999999	194.0500031	205.0599976
?            	           +++++++	          ^^^^^^^^	          ^^^^^^^^

Not sure whether this is an issue with the code or just a shortcoming in the test.

@megies
Copy link
Member

megies commented Nov 30, 2023

Can you please fix the code formatting before we look at details of test fails, so we can see clearer? Thanks!

PEP8 fails are in the bot comments on the code tab or just run flake8 on command line.

~/git/obspy/obspy「racin..ter」$ flake8
./io/ascii/core.py:41:1: F401 'fileinput.filename' imported but unused
./io/ascii/core.py:61:15: F811 redefinition of unused 'filename' from line 41
./io/ascii/core.py:66:80: E501 line too long (86 > 79 characters)
./io/ascii/core.py:76:28: E231 missing whitespace after ','
./io/ascii/core.py:81:1: W293 blank line contains whitespace
./io/ascii/core.py:83:32: E231 missing whitespace after ','
./io/ascii/core.py:88:28: E231 missing whitespace after ','
./io/ascii/core.py:89:38: E231 missing whitespace after ','
./io/ascii/core.py:97:16: F811 redefinition of unused 'filename' from line 41
./io/ascii/core.py:102:80: E501 line too long (87 > 79 characters)
./io/ascii/core.py:112:28: E231 missing whitespace after ','
./io/ascii/core.py:117:1: W293 blank line contains whitespace
./io/ascii/core.py:119:32: E231 missing whitespace after ','
./io/ascii/core.py:124:28: E231 missing whitespace after ','
./io/ascii/core.py:125:38: E231 missing whitespace after ','
./io/ascii/core.py:133:17: F811 redefinition of unused 'filename' from line 41
./io/ascii/core.py:154:24: E231 missing whitespace after ','
./io/ascii/core.py:158:1: W293 blank line contains whitespace
./io/ascii/core.py:176:28: E231 missing whitespace after ','
./io/ascii/core.py:207:18: F811 redefinition of unused 'filename' from line 41
./io/ascii/core.py:228:24: E231 missing whitespace after ','
./io/ascii/core.py:232:1: W293 blank line contains whitespace
./io/ascii/core.py:250:28: E231 missing whitespace after ','
./io/ascii/core.py:281:26: F811 redefinition of unused 'filename' from line 41
./io/ascii/core.py:348:24: E231 missing whitespace after ','
./io/ascii/core.py:351:27: E231 missing whitespace after ','
./io/ascii/core.py:352:1: W293 blank line contains whitespace
./io/ascii/core.py:394:28: E231 missing whitespace after ','
./io/ascii/core.py:398:27: F811 redefinition of unused 'filename' from line 41
./io/ascii/core.py:472:24: E231 missing whitespace after ','
./io/ascii/core.py:475:27: E231 missing whitespace after ','
./io/ascii/core.py:476:1: W293 blank line contains whitespace
./io/ascii/core.py:508:28: E231 missing whitespace after ','

Now adherent to pep8
@megies
Copy link
Member

megies commented Feb 22, 2024

I'm really sorry, I believe this is done in a more generalized way as part of #3346 which should get merged soon. My bad for not realizing this was already being worked on when you first opened this PR @raciner.

@megies megies added the duplicate Duplicate of another issue label Feb 22, 2024
@megies
Copy link
Member

megies commented May 22, 2024

I believe this is done now with #3240 merged. Again sorry for overlooking this one for some time.

@megies megies closed this May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Duplicate of another issue .io issues generally related to our read/write plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants