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

io.open → open #1421

Merged
merged 3 commits into from
Oct 30, 2023
Merged

io.open → open #1421

merged 3 commits into from
Oct 30, 2023

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented May 28, 2023

In Python 3, io.open() is an alias for the builtin open() function:
https://docs.python.org/3/library/io.html#io.open

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions bot added needs release notes Automatically applied to PRs which haven't added release notes and removed needs release notes Automatically applied to PRs which haven't added release notes labels May 28, 2023
@DimitriPapadopoulos DimitriPapadopoulos changed the title io.open() has become an alias for open() io.open() → open() May 29, 2023
@DimitriPapadopoulos DimitriPapadopoulos changed the title io.open() → open() io.open → open May 29, 2023
@DimitriPapadopoulos DimitriPapadopoulos marked this pull request as draft May 29, 2023 12:18
@DimitriPapadopoulos
Copy link
Contributor Author

That's disturbing. Despite io.open() being (supposedly) an alias for open(), changing to open() fails. The error message is unclear, that's perhaps a real issue.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented May 31, 2023

Got it. File convenience.py defines a function open that shadows the builtin open 🤯

def open(store: StoreLike = None, mode: str = "a", *, zarr_version=None, path=None, **kwargs):

Not really convenient if you ask me.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented May 31, 2023

This should probably be fixed by changing the name of the local function open, perhaps to zarr_open.

Then change:

from zarr.convenience import (consolidate_metadata, copy, copy_all, copy_store,
load, open, open_consolidated, save, save_array,
save_group, tree)

to:

from zarr.convenience import (consolidate_metadata, copy, copy_all, copy_store,
                              load, open_consolidated, save, save_array,
                              save_group, tree)
from zarr.convenience import zarr_open as open

Thoughts?

@codecov
Copy link

codecov bot commented Jul 19, 2023

Codecov Report

Merging #1421 (9017ac2) into main (1ed37f5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 9017ac2 differs from pull request most recent head 2478f46. Consider uploading reports for the commit 2478f46 to get more accurate results

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #1421   +/-   ##
========================================
  Coverage   99.99%   100.00%           
========================================
  Files          37        37           
  Lines       14740     14735    -5     
========================================
- Hits        14739     14735    -4     
+ Misses          1         0    -1     
Files Coverage Δ
zarr/convenience.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

@d-v-b
Copy link
Contributor

d-v-b commented Jul 19, 2023

@DimitriPapadopoulos

This should probably be fixed by changing the name of the local function open, perhaps to zarr_open.

I have no objection to this strategy. Do you want to pursue that in this PR, or elsewhere?

@DimitriPapadopoulos
Copy link
Contributor Author

Probably another PR.

After thinking more about it, nothing's wrong with an open function, it should just be used as
zarr.convenience.open or from zarr.convenience import open as zarr_open.

In Python 3, io.open() is an alias for the builtin open() function:
https://docs.python.org/3/library/io.html#io.open
@@ -491,7 +492,7 @@ def __init__(self, log):
elif callable(log):
self.log_func = log
elif isinstance(log, str):
self.log_file = io.open(log, mode="w")
self.log_file = _builtin_open(log, mode="w")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we certain this is the only use of io.open?

Copy link
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Sep 24, 2023

Choose a reason for hiding this comment

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

I think so. A grep of io.open yields:

$ fgrep -R io.open --exclude-dir=.git
zarr/convenience.py:            self.log_file = io.open(log, mode="w")
build/lib/zarr/convenience.py:            self.log_file = io.open(log, mode='w')
$ 

And a grep of open( in zarr/convenience.py yields:

$ grep -R 'open(' zarr/convenience.py 
def open(store: StoreLike = None, mode: str = "a", *, zarr_version=None, path=None, **kwargs):
        >>> zw = zarr.open(store, mode='w', shape=100, dtype='i4')  # open new array
        >>> za = zarr.open(store, mode='a')  # open existing array for reading and writing
        >>> zr = zarr.open(store, mode='r')  # open existing array read-only
        >>> gw = zarr.open(store, mode='w')  # open new group, overwriting previous data
        >>> ga = zarr.open(store, mode='a')  # open existing group for reading and writing
        >>> gr = zarr.open(store, mode='r')  # open existing group read-only
            self.log_file = io.open(log, mode="w")
    return open(store=meta_store, chunk_store=chunk_store, mode=mode, path=path, **kwargs)
$ 

Do you have a specific concern, anything I may have overlooked?

Copy link
Contributor

Choose a reason for hiding this comment

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

No not really. Just wanted to make sure we only have to do this once.

Copy link
Contributor

@rabernat rabernat left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this PR!

@joshmoore joshmoore merged commit 7aac447 into zarr-developers:main Oct 30, 2023
15 of 16 checks passed
dstansby pushed a commit to dstansby/zarr-python that referenced this pull request Oct 31, 2023
In Python 3, io.open() is an alias for the builtin open() function:
https://docs.python.org/3/library/io.html#io.open

Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
Co-authored-by: Josh Moore <josh@openmicroscopy.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants