-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[TEST] Add two more parameters to the test_dti_add_sub_nonzero_mth_offset #26392
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26392 +/- ##
==========================================
- Coverage 91.69% 91.68% -0.01%
==========================================
Files 174 174
Lines 50749 50749
==========================================
- Hits 46534 46530 -4
- Misses 4215 4219 +4
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #26392 +/- ##
==========================================
- Coverage 91.75% 91.74% -0.01%
==========================================
Files 174 174
Lines 50761 50761
==========================================
- Hits 46574 46571 -3
- Misses 4187 4190 +3
Continue to review full report at Codecov.
|
lgtm. @jbrockmendel |
mth = getattr(date, op) | ||
result = mth(offset) | ||
tm.assert_equal(result, exp) | ||
|
||
expected = pd.Index(exp, tz=tz) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTimeIndex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason not to do this? passing tz
to Index
is allowed, but not encouraged
@@ -1435,27 +1435,38 @@ def test_dt64arr_add_sub_offset_ndarray(self, tz_naive_fixture, | |||
expected = tm.box_expected(expected, box_with_array) | |||
tm.assert_equal(res, expected) | |||
|
|||
@pytest.mark.parametrize("box", [pd.Index, pd.Series, pd.DataFrame]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use box_with_array fixture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case to_array
of box_with_array
, the DatetimeArray after addition of an offset of month and day doesn't have any freq. But adding an offset of month only results in freq. May I assert the equality of array values only by assert_numpy_array_equal
?
In [18]: arr = pd.date_range(start='01 Jan 2014', end='01 Jan 2017', freq='AS').
...: array
In [19]: arr
Out[19]:
<DatetimeArray>
['2014-01-01 00:00:00', '2015-01-01 00:00:00', '2016-01-01 00:00:00',
'2017-01-01 00:00:00']
Length: 4, dtype: datetime64[ns]
In [20]: offset1 = pd.DateOffset(months=3, days=10)
In [21]: offset1
Out[21]: <DateOffset: days=10, months=3>
In [22]: (arr + offset1).freq is None
Out[22]: True
In [23]: offset2 = pd.DateOffset(months=3)
In [24]: (arr + offset2).freq
Out[24]: <YearBegin: month=4>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case to_array of box_with_array, the DatetimeArray after addition of an offset of month and day doesn't have any freq.
If DatetimeIndex + DateOffset behaves differently from DatetimeArray + DateOffset, that's a bug and should be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference starts at L384:
pandas/pandas/core/arrays/datetimes.py
Lines 381 to 384 in d3a1912
elif freq_infer: | |
# Set _freq directly to bypass duplicative _validate_frequency | |
# check. | |
result._freq = to_offset(result.inferred_freq) |
There is a frequency
AS-JAN
defined to denote the beginning of Jan, but no frequency defined for a specific date.ref.: https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#anchored-offsets
In [2]: arr1 = pd.DatetimeIndex(['01 Jan 2014', '01 Jan 2015', '01 Jan 2016', '0
...: 1 Jan 2017']).array
In [3]: arr2 = pd.DatetimeIndex(['11 Apr 2014', '11 Apr 2015', '11 Apr 2016', '1
...: 1 Apr 2017']).array
In [4]: arr1.inferred_freq
Out[4]: 'AS-JAN'
In [5]: arr2.inferred_freq
In [6]: arr2.inferred_freq is None
Out[6]: True
We can set result._freq
to DateOffset(month, day)
, when inferred_freq
returns None
. Is it what we want? (This change would break 19 tests in test_datetime64.py)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was a miscommunication and I got confused. Hopefully I've got it right now, let's double-check. Thanks for bearing with me here.
The following should be true for any DatetimeIndex dti
and any DateOffset offset
:
(dti + offset).freq == (dti.array + offset).freq
Are you saying there is a counter-example? If not, I don't see why you can't use box_with_array
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(dti + offset).freq == (dti.array + offset).freq
This equality holds.
I add the freq check of the Index myself, because assert_index_equal
doesn't check the freq. The freq of the Index match the expected frequency as the array does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks.
I think there is an Issue for having assert_index_equal
check freq
for appropriate subclasses, if that's something you're interested in fixing.
@jbrockmendel merge if ok with the responses. |
@jbrockmendel Please tell me if you have anything to implement? |
LGTM, merging. |
Thanks @makbigc |
…fset (pandas-dev#26392) * Add two more parameters to the test * Add array into the boy and add parameter freq
git diff upstream/master -u -- "*.py" | flake8 --diff