question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tuples not accepted for dim keyword.

See original GitHub issue

Describe the bug When passing dimensions to dim=... in .verify(...), tuples break it and they should not, since it’s a base python type similar to list.

Code Sample

import climpred

hind = climpred.tutorial.load_dataset("CESM-DP-SST-3D")
verif = climpred.tutorial.load_dataset("FOSI-SST-3D")
hindcast = climpred.HindcastEnsemble(hind).add_observations(verif)

# works
hindcast.verify(
    metric="acc", comparison="e2o", alignment="maximize", dim=("nlat")
)


# works
hindcast.verify(
    metric="acc", comparison="e2o", alignment="maximize", dim=["init", "nlat"]
)

# breaks
hindcast.verify(
    metric="acc", comparison="e2o", alignment="maximize", dim=("init", "nlat")
)

Expected behavior We should be able to pass in tuples of len > 1 to dim.

Additional context Should be an easy fix. Track wherever this error is thrown:

ValueError: Expected `dim` as `str`, `list` or None, found ('nlat', 'nlon') as type <class 'tuple'>.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ahuang11commented, Nov 2, 2020

If you want any Iterable (str, list, tuple, np.array, pd.Series, xr.DataArray), you can do

from collections.abc import Iterable
isisinstance(dim, Iterable)

Or define a constant somewhere

VALID_DIM_TYPES = (list, tuple, str)
isinstance(dim ,VALID_DIM_TYPES)
0reactions
ahuang11commented, Nov 3, 2020

Haha yea true. The most dimensions I’ve worked with experiment, member, initialization, forecast_step, level, lat, lon

But ( just reminded me of pd.cut and the results are like (3, 4], where ] is inclusive of 4 or something

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Members, Tuples, and Sets (MDX)
MDX provides several functions that return sets. Explicitly typing tuples and enclosing them in braces is not the only way to retrieve a...
Read more >
How to flatten a tuple in python - Stack Overflow
First it will be checked if type is tuple, if not, it "tuples" the argument ... for each value of the internal tuple...
Read more >
Python Return Multiple Values – How to Return a Tuple, List ...
In this article, we'll explore how to return multiple values from these data structures: tuples, lists, and dictionaries. Tuples. A tuple is an ......
Read more >
Better support for operators that return (named) tuples of tensors
In the max example above, in particular, adding a dim argument to max requires rewriting the left-hand side of that expression to make...
Read more >
Mapping over a tuple | Apple Developer Forums
I currently have code that looks like this: let pxLeft = abs(left.spec.pixelsForDimension(left.dimension, imageSize: size)). let pxRight = abs(right.spec.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found