pangeo-data / scikit-downscale

Statistical climate downscaling in Python
https://scikit-downscale.readthedocs.io/en/latest/
Apache License 2.0
185 stars 47 forks source link

[BUG] AttributeError: 'tuple' object has no attribute 'month' #35

Closed jhamman closed 4 years ago

jhamman commented 4 years ago

We have a failing test in our test suite right now. I'm looking into it and will open a PR with a fix asap.

2020-08-04T22:57:29.6502436Z =================================== FAILURES ===================================
2020-08-04T22:57:29.6502823Z ______________________ test_linear_model[BcsdTemperature] ______________________
2020-08-04T22:57:29.6503098Z 
2020-08-04T22:57:29.6504069Z model_cls = <class 'skdownscale.pointwise_models.bcsd.BcsdTemperature'>
2020-08-04T22:57:29.6504452Z 
2020-08-04T22:57:29.6504792Z     @pytest.mark.parametrize(
2020-08-04T22:57:29.6505411Z         'model_cls', [BcsdTemperature, PureAnalog, AnalogRegression, ZScoreRegressor]
2020-08-04T22:57:29.6505908Z     )
2020-08-04T22:57:29.6506359Z     def test_linear_model(model_cls):
2020-08-04T22:57:29.6506781Z     
2020-08-04T22:57:29.6507097Z         n = 365
2020-08-04T22:57:29.6507452Z         # TODO: add test for time other time ranges (e.g. < 365 days)
2020-08-04T22:57:29.6508070Z         index = pd.date_range('2019-01-01', periods=n)
2020-08-04T22:57:29.6508460Z     
2020-08-04T22:57:29.6509057Z         X = pd.DataFrame({'foo': np.sin(np.linspace(-10 * np.pi, 10 * np.pi, n)) * 10}, index=index)
2020-08-04T22:57:29.6509467Z         y = X + 2
2020-08-04T22:57:29.6509793Z     
2020-08-04T22:57:29.6510108Z         model = model_cls()
2020-08-04T22:57:29.6510548Z         model.fit(X, y)
2020-08-04T22:57:29.6510840Z >       model.predict(X)
2020-08-04T22:57:29.6511097Z 
2020-08-04T22:57:29.6511401Z skdownscale/test/test_pointwise_models.py:83: 
2020-08-04T22:57:29.6511724Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-08-04T22:57:29.6512056Z skdownscale/pointwise_models/bcsd.py:186: in predict
2020-08-04T22:57:29.6512377Z     X_shift = self._remove_climatology(X_rolling_mean, self._x_climo)
2020-08-04T22:57:29.6512918Z skdownscale/pointwise_models/bcsd.py:205: in _remove_climatology
2020-08-04T22:57:29.6513339Z     for key, group in obj.groupby(self.time_grouper):
2020-08-04T22:57:29.6513987Z /opt/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/pandas/core/frame.py:6514: in groupby
2020-08-04T22:57:29.6514376Z     dropna=dropna,
2020-08-04T22:57:29.6514980Z /opt/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/pandas/core/groupby/groupby.py:533: in __init__
2020-08-04T22:57:29.6515369Z     dropna=self.dropna,
2020-08-04T22:57:29.6515970Z /opt/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/pandas/core/groupby/grouper.py:805: in get_grouper
2020-08-04T22:57:29.6516364Z     if not isinstance(gpr, Grouping)
2020-08-04T22:57:29.6516956Z /opt/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/pandas/core/groupby/grouper.py:519: in __init__
2020-08-04T22:57:29.6517473Z     self.grouper = self.index.map(self.grouper)
2020-08-04T22:57:29.6518093Z /opt/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/pandas/core/indexes/base.py:4788: in map
2020-08-04T22:57:29.6518506Z     new_values = super()._map_values(mapper, na_action=na_action)
2020-08-04T22:57:29.6519132Z /opt/hostedtoolcache/Python/3.7.8/x64/lib/python3.7/site-packages/pandas/core/base.py:1160: in _map_values
2020-08-04T22:57:29.6519665Z     new_values = map_f(values, mapper)
2020-08-04T22:57:29.6520013Z pandas/_libs/lib.pyx:2388: in pandas._libs.lib.map_infer
2020-08-04T22:57:29.6520346Z     ???
2020-08-04T22:57:29.6520674Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-08-04T22:57:29.6520942Z 
2020-08-04T22:57:29.6521489Z x = (1, Timestamp('2019-01-01 00:00:00'))
2020-08-04T22:57:29.6521820Z 
2020-08-04T22:57:29.6522129Z     def MONTH_GROUPER(x):
2020-08-04T22:57:29.6522463Z >       return x.month
2020-08-04T22:57:29.6523020Z E       AttributeError: 'tuple' object has no attribute 'month'
2020-08-04T22:57:29.6523466Z 
2020-08-04T22:57:29.6523800Z skdownscale/pointwise_models/bcsd.py:14: AttributeError
2020-08-04T22:57:29.6524134Z =============================== warnings summary ===============================