Skip to content

is dot syntax gone now? #2991

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

Closed
christine-e-smit opened this issue Apr 16, 2025 · 4 comments
Closed

is dot syntax gone now? #2991

christine-e-smit opened this issue Apr 16, 2025 · 4 comments
Labels
bug Potential issues with the zarr-python library

Comments

@christine-e-smit
Copy link
Contributor

Zarr version

v3.0.6

Numcodecs version

0.15.1

Python Version

3.13.3

Operating System

M<ac

Installation

using conda

Description

I don't actually know what you call this, but I'm calling it dot syntax for accessing arrays. With zarr version 2.18.4, I can do the following:

import zarr
import numpy as np
z = zarr.open("two.zarr",mode="w")
d = z.create_dataset("d",shape=(2),dtype=np.int32)
# this works!
z.d

But with zarr version 3.0.6, the following throws an exception:

import zarr
import numpy as np
z = zarr.open("three.zarr",mode="w")
d = z.create_array("d",shape=(2),dtype=np.int32)
# this now throws the exception "AttributeError: 'Group' object has no attribute 'd'"
z.d

Is this expected? Unexpected? I didn't see anything in the 3.0 Migration Guide, but it wouldn't surprise me if I missed something.

Steps to reproduce

import zarr
import numpy as np
z = zarr.open("three.zarr",mode="w")
d = z.create_array("d",shape=(2),dtype=np.int32)
# this now throws the exception "AttributeError: 'Group' object has no attribute 'd'"
z.d

Additional output

No response

@christine-e-smit christine-e-smit added the bug Potential issues with the zarr-python library label Apr 16, 2025
@d-v-b
Copy link
Contributor

d-v-b commented Apr 16, 2025

hi @christine-e-smit, yes the "." syntax for getting group members has been removed in 3.0. To get a member of a group named "foo", use group["foo"]

I suspect we simply failed to mention this in the migration guide. I can fix this shortly.

@christine-e-smit
Copy link
Contributor Author

Thank you for the clarification. I've submitted a pull request with some suggested language for the documentation.

@rabernat
Copy link
Contributor

@christine-e-smit - did you find this syntax valuable?

For context, IIRC it was removed because many IDEs (e.g. JupyterLab, VCCode) will introspect python objects to provide auto-completion. With this dot syntax, that would actually trigger listing of groups, reading metadata, etc. operations with significant side effects and performance implications.

@christine-e-smit
Copy link
Contributor Author

Interesting! I never personally ran into the IDE issue in Visual Studio Code, but I can see how it could be painful. I think I've used both g.x and g["x"] syntax without thinking terribly deeply about it, so I don't think I'll miss the "." syntax. I'm more concerned that finding all the instances where we used "." syntax is going to be tricky because it's not something you can just grep for. But if it's causing that many issues with IDEs, then I understand why you've dropped it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Potential issues with the zarr-python library
Projects
None yet
Development

No branches or pull requests

3 participants