home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 573416265

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/3673#issuecomment-573416265 https://api.github.com/repos/pydata/xarray/issues/3673 573416265 MDEyOklzc3VlQ29tbWVudDU3MzQxNjI2NQ== 6628425 2020-01-12T13:38:26Z 2020-01-12T13:38:26Z MEMBER

So there are two classes of failures here:

  1. With pandas master, adding a CFTimeIndex to a TimedeltaIndex no longer returns a CFTimeIndex; instead it returns a generic Index of cftime objects.
Failure

``` 2020-01-07T19:19:39.0297443Z =================================== FAILURES =================================== 2020-01-07T19:19:39.0495451Z _________________ test_timedeltaindex_add_cftimeindex[365_day] _________________ 2020-01-07T19:19:39.0496702Z 2020-01-07T19:19:39.0498391Z calendar = '365_day' 2020-01-07T19:19:39.0499052Z 2020-01-07T19:19:39.0500036Z @requires_cftime 2020-01-07T19:19:39.0500669Z @pytest.mark.parametrize("calendar", _CFTIME_CALENDARS) 2020-01-07T19:19:39.0501986Z def test_timedeltaindex_add_cftimeindex(calendar): 2020-01-07T19:19:39.0502556Z a = xr.cftime_range("2000", periods=5, calendar=calendar) 2020-01-07T19:19:39.0503384Z deltas = pd.TimedeltaIndex([timedelta(days=2) for _ in range(5)]) 2020-01-07T19:19:39.0503635Z result = deltas + a 2020-01-07T19:19:39.0504330Z expected = a.shift(2, "D") 2020-01-07T19:19:39.0505283Z assert result.equals(expected) 2020-01-07T19:19:39.0506265Z > assert isinstance(result, CFTimeIndex) 2020-01-07T19:19:39.0507151Z E AssertionError: assert False 2020-01-07T19:19:39.0508329Z E + where False = isinstance(Index([2000-01-03 00:00:00, 2000-01-04 00:00:00, 2000-01-05 00:00:00,\n 2000-01-06 00:00:00, 2000-01-07 00:00:00],\n dtype='object'), CFTimeIndex) ```

  1. With pandas master, casting a DatetimeIndex (i.e. the result of a call to to_datetime) to an array now returns a NumPy array of timezone-aware Timestamp objects, rather than timezone-naive NumPy array of dtype datetime64[ns].
Failure

``` 2020-01-07T19:19:39.0552973Z ____ test_cf_datetime_nan[num_dates1-days since 2000-01-01-expected_list1] _____ 2020-01-07T19:19:39.0553281Z 2020-01-07T19:19:39.0553765Z num_dates = [nan, 0], units = 'days since 2000-01-01' 2020-01-07T19:19:39.0554887Z expected_list = ['NaT', '2000-01-01T00:00:00Z'] 2020-01-07T19:19:39.0555104Z 2020-01-07T19:19:39.0555251Z @arm_xfail 2020-01-07T19:19:39.0555406Z @requires_cftime 2020-01-07T19:19:39.0555551Z @pytest.mark.parametrize( 2020-01-07T19:19:39.0555693Z ["num_dates", "units", "expected_list"], 2020-01-07T19:19:39.0555849Z [ 2020-01-07T19:19:39.0556225Z ([np.nan], "days since 2000-01-01", ["NaT"]), 2020-01-07T19:19:39.0556674Z ([np.nan, 0], "days since 2000-01-01", ["NaT", "2000-01-01T00:00:00Z"]), 2020-01-07T19:19:39.0556881Z ( 2020-01-07T19:19:39.0557026Z [np.nan, 0, 1], 2020-01-07T19:19:39.0557374Z "days since 2000-01-01", 2020-01-07T19:19:39.0558208Z ["NaT", "2000-01-01T00:00:00Z", "2000-01-02T00:00:00Z"], 2020-01-07T19:19:39.0558355Z ), 2020-01-07T19:19:39.0558466Z ], 2020-01-07T19:19:39.0558591Z ) 2020-01-07T19:19:39.0559984Z def test_cf_datetime_nan(num_dates, units, expected_list): 2020-01-07T19:19:39.0560153Z with warnings.catch_warnings(): 2020-01-07T19:19:39.0560559Z warnings.filterwarnings("ignore", "All-NaN") 2020-01-07T19:19:39.0560733Z actual = coding.times.decode_cf_datetime(num_dates, units) 2020-01-07T19:19:39.0561076Z # use pandas because numpy will deprecate timezone-aware conversions 2020-01-07T19:19:39.0561235Z expected = pd.to_datetime(expected_list) 2020-01-07T19:19:39.0561532Z > assert_array_equal(expected, actual) 2020-01-07T19:19:39.0561669Z E AssertionError: 2020-01-07T19:19:39.0561785Z E Arrays are not equal 2020-01-07T19:19:39.0561899Z E 2020-01-07T19:19:39.0562138Z E Mismatched elements: 2 / 2 (100%) 2020-01-07T19:19:39.0562505Z E x: array([NaT, Timestamp('2000-01-01 00:00:00+0000', tz='UTC')], dtype=object) 2020-01-07T19:19:39.0563375Z E y: array([ 'NaT', '2000-01-01T00:00:00.000000000'], 2020-01-07T19:19:39.0563710Z E dtype='datetime64[ns]') 2020-01-07T19:19:39.0564285Z 2020-01-07T19:19:39.0564914Z xarray/tests/test_coding_times.py:455: AssertionError ```

(2) is simple. Basically due to a planned change<sup>1</sup> in pandas, the test needs to be edited. In xarray we still expect decode_cf_datetime to return timezone-naive dates. Therefore we need to make sure that we are comparing against a timezone-naive reference.

(1) is trickier; I'm not sure if it's something we should raise in the pandas issue tracker. Essentially we rely on TimedeltaIndex.__add__(other) to return NotImplemented when other is a CFTimeIndex; this way it will resort to using CFTimeIndex.__radd__ instead. It looks like recent code changes in pandas broke this.


<sup>1</sup>See this FutureWarning: FutureWarning: Converting timezone-aware DatetimeArray to timezone-naive ndarray with 'datetime64[ns]' dtype. In the future, this will return an ndarray with 'object' dtype where each element is a 'pandas.Timestamp' with the correct 'tz'. To accept the future behavior, pass 'dtype=object'. To keep the old behavior, pass 'dtype="datetime64[ns]"'. exec(code_obj, self.user_global_ns, self.user_ns)

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  547012915
Powered by Datasette · Queries took 1.051ms · About: xarray-datasette