-
Notifications
You must be signed in to change notification settings - Fork 75
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
Types not the same for indexing vs. iteration of catalog.datasets #361
Comments
100% chance this is because |
Hrmmm... now that I think about this with just a bit more thought, this is standard d = {'a': 1, 'b':2, 'c':3}
print(type(d['a']))
# <class 'int'>
for i in d:
print(type(i))
# <class 'str'>
... So right now |
Ah, right you are, this is very Pythonic dict behavior once you recognize the keys are the dataset.name strings. Would you be open to a docstring change to make the iteration and indexing behavior more explicit? Are there other recommended places to document this behavior?
… On Apr 8, 2021, at 14:53, Ryan May ***@***.***> wrote:
Hrmmm... now that I think about this with just a bit more thought, this is standard dict behavior. For this code:
d = {'a': 1, 'b':2, 'c':3}
print(type(d['a']))
# <class 'int'>
for i in d:
print(type(i))
# <class 'str'>
...
So right now DatasetCollection works exactly like a python dictionary. This is because you can get items out of DatasetCollection by position (i.e. [0]) or by name (i.e. my_data_file_name.nc). And to be clear, it's always had the dictionary semantics--we added later on the ability to use [0]. I'm not sure whether it'd be a good idea to fundamentally change those semantics...
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
👍 to updating the docstring. I can't think of anything other place unless we add some proper narrative documentation about |
OK, PR for the doc fix is above. I suggest also updating section 3. of the workshop tutorial on Siphon, which is the code I was copying when I confused myself. |
This continues to be subtle and surprising to me. I thought I understood well enough to write this up for the tutorial, and then My troubleshooting was made further confusing by the fact that cat.datasets[1:3] looks like a list of keys, and so the repr might be a target for a usability fix? I actually built in this latest confusion as a teachable moment in the siphon tutorial notebook. The slicing behavior is not explicitly documented in my docstring change. |
Try to include:
cat.datasets
, the return type is a Dataset object, but when iterating the return type is a string.cat.datasets
, and developed a parsing method based on that return type. That information was inaccurate when I converted the logic to a function to loop over datasets.python --version
: Python 3.6.12The text was updated successfully, but these errors were encountered: