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

unit tests failing because of timeslice issue #96

Closed
dgergel opened this issue Jul 2, 2021 · 3 comments · Fixed by #95
Closed

unit tests failing because of timeslice issue #96

dgergel opened this issue Jul 2, 2021 · 3 comments · Fixed by #95
Labels
bug Something isn't working

Comments

@dgergel
Copy link
Member

dgergel commented Jul 2, 2021

We're currently getting a bunch of test errors coming from Line 98 in core.py in the adjust quantile mapping function coming from how we're slicing time:

=================================== FAILURES ===================================
__________ test_adjust_quantiledeltamapping_year_kind[additive kind] ___________

variable_kind = '+', expected = -1.0

    @pytest.mark.parametrize(
        "variable_kind, expected",
        [
            pytest.param("+", -1.0, id="additive kind"),
            pytest.param("*", 0.5, id="multiplicative kind"),
        ],
    )
    def test_adjust_quantiledeltamapping_year_kind(variable_kind, expected):
        """Test that QDM 'kind' is handled"""
        # Setup input data.
        target_variable = "fakevariable"
        n_simdays = 100 * 365  # 100 years of daily simulation.
    
        model_bias = 2.0
        ts_sim = np.ones(n_simdays, dtype=np.float64)
        sim = _timeseriesfactory(
            ts_sim * model_bias, start_dt="2015-01-01", variable_name=target_variable
        )
    
        target_year = 2026
    
        # Yes, I'm intentionally training the QDM to a different bias. This is to
        # spurn a difference between "kind" adjustments...
        qdm = _train_simple_qdm(
            target_variable="fakevariable", kind=variable_kind, additive_bias=model_bias + 1
        )
>       adjusted_ds = adjust_quantiledeltamapping_year(
            simulation=sim,
            qdm=qdm,
            year=target_year,
            variable=target_variable,
        )

opt/dodola/dodola/tests/test_core.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
opt/dodola/dodola/core.py:98: in adjust_quantiledeltamapping_year
    simulation = simulation[variable].sel(
opt/conda/lib/python3.9/site-packages/xarray/core/dataarray.py:1271: in sel
    ds = self._to_temp_dataset().sel(
opt/conda/lib/python3.9/site-packages/xarray/core/dataset.py:2365: in sel
    pos_indexers, new_indexes = remap_label_indexers(
opt/conda/lib/python3.9/site-packages/xarray/core/coordinates.py:421: in remap_label_indexers
    pos_indexers, new_indexes = indexing.remap_label_indexers(
opt/conda/lib/python3.9/site-packages/xarray/core/indexing.py:274: in remap_label_indexers
    idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
opt/conda/lib/python3.9/site-packages/xarray/core/indexing.py:121: in convert_label_indexer
    indexer = index.slice_indexer(
opt/conda/lib/python3.9/site-packages/pandas/core/indexes/base.py:5686: in slice_indexer
    start_slice, end_slice = self.slice_locs(start, end, step=step)
opt/conda/lib/python3.9/site-packages/pandas/core/indexes/base.py:5888: in slice_locs
    start_slice = self.get_slice_bound(start, "left")
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = CFTimeIndex([2015-01-01 00:00:00, 2015-01-02 00:00:00, 2015-01-03 00:00:00,
             2015-01-04 00:00:00, 2015-01-...-30 00:00:00,
             2114-12-31 00:00:00],
            dtype='object', length=36500, calendar='noleap', freq='D')
label = '2015-12-17', side = 'left', kind = None

    def get_slice_bound(self, label, side: str_t, kind=None) -> int:
        """
        Calculate slice bound that corresponds to given label.
    
        Returns leftmost (one-past-the-rightmost if ``side=='right'``) position
        of given label.
    
        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : {'loc', 'getitem'} or None
    
        Returns
        -------
        int
            Index of label.
        """
        assert kind in ["loc", "getitem", None]
    
        if side not in ("left", "right"):
            raise ValueError(
                "Invalid value for side kwarg, must be either "
                f"'left' or 'right': {side}"
            )
    
        original_label = label
    
        # For datetime indices label may be a string that has to be converted
        # to datetime boundary according to its resolution.
>       label = self._maybe_cast_slice_bound(label, side)
E       TypeError: _maybe_cast_slice_bound() missing 1 required positional argument: 'kind'

opt/conda/lib/python3.9/site-packages/pandas/core/indexes/base.py:5798: TypeError

Edit: Can see this in PR #95 CI job https://github.com/ClimateImpactLab/dodola/runs/2975167693.

@brews
Copy link
Member

brews commented Jul 2, 2021

@dgergel Maybe an upstream issue issue from a recent upgrade to CFTimeIndex?

I don't think we have this package pinned.

Edit: Pure speculation on my part.

@brews brews added the bug Something isn't working label Jul 2, 2021
@brews
Copy link
Member

brews commented Jul 2, 2021

@dgergel Try adding pandas=1.2.5 # Pkg not a direct dodola dependency, workaround for #96 to the conda part of environment.yaml. See if that works.

@brews
Copy link
Member

brews commented Jul 2, 2021

I think this was resolved by PR #96? Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants