-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
BUG/TST/REF: Datetimelike Arithmetic Methods #23215
Conversation
…, add missing tests
attribs = self._get_attributes_dict() | ||
if not is_period_dtype(self): | ||
attribs['freq'] = None | ||
return self._simple_new(result, **attribs) |
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.
This is only used once outside of tests. Much less verbose to inline.
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.
hah I just made a comment on PeriodArray about re-using this.
if other is NaT: | ||
# In this case we specifically interpret NaT as a datetime, not | ||
# the timedelta interpretation we would get by returning self + NaT | ||
result = self.asi8.view('m8[ms]') + NaT.to_datetime64() | ||
return DatetimeArrayMixin(result) |
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.
This fixes the bug in TimedeltaIndex + np.timedelta64('NaT')
result = checked_add_with_arr(i8, other.value, | ||
arr_mask=self._isnan) | ||
result = self._maybe_mask_results(result, fill_value=iNaT) | ||
return DatetimeArrayMixin(result, tz=other.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.
This fixes a bug with failing to attach tz
@pytest.mark.parametrize('other', [pd.Timestamp.now(), | ||
pd.Timestamp.now().to_pydatetime(), | ||
pd.Timestamp.now().to_datetime64()]) | ||
def test_pi_add_sub_datetime(self, other): |
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.
This behavior is unchanged; it was just an untested case.
Codecov Report
@@ Coverage Diff @@
## master #23215 +/- ##
==========================================
- Coverage 92.16% 92.16% -0.01%
==========================================
Files 166 166
Lines 51224 51206 -18
==========================================
- Hits 47212 47192 -20
- Misses 4012 4014 +2
Continue to review full report at Codecov.
|
Hello @jbrockmendel! Thanks for updating the PR.
|
@datapythonista where should I be looking for the explanation of why the linting is failing? It used to tell me right above the "exited wth code 1" line From Travis log:
|
https://travis-ci.org/pandas-dev/pandas/jobs/443307753#L2918 I search for |
It's the imports I think?
|
Yah, I think #23231 should have just fixed it. I'll re-push in a bit. |
Updated with additional bugfixes:
|
ping on green |
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.
You did a rename of things like _sub_datelike_dti
to _sub_datetime_arraylike
, which is good, but the same could be done for _sub_delta_tdi
and others (can maybe also be left for another PR, as those are touched less here)
Added some minor comments/questions, looks good to me for the rest
@@ -844,7 +753,7 @@ def _add_delta_td(self, other): | |||
# delta_to_nanoseconds(delta). Because delta here is an integer, | |||
# delta_to_nanoseconds will return it unchanged. | |||
ordinals = super(PeriodArray, self)._add_delta_td(delta) | |||
return type(self)(ordinals, self.freq) | |||
return ordinals | |||
|
|||
def _add_delta_tdi(self, other): |
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 superclass version seems to return integers, but this an actual PeriodArray?
Can you add a comment indicating the types?
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 superclass version seems to return integers, but this an actual PeriodArray?
Both this and the superclass version return i8 array. The superclass has a brief docstring to that effect.
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 then add a comment on this function indicating the types? That really makes it easier to read through this code
But, to my original question: this function uses _addsub_int_array
, which is defined a little bit above to return a PeriodArray, and not a i8 array.
I assume in practice this is not really a problem, because the code that converts the i8 array to PeriodArray, will also accept a PeriodArray.
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.
Good catch, I must have lost track of this somewhere in the rebase process. Fixed to correctly return an i8 array, and brief docstrings added indicating types.
@jorisvandenbossche anything else to address or can i ping jeff? |
will look tonight |
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.
minor comments, needds a rebase, ping on green.
@@ -221,7 +221,7 @@ def hasnans(self): | |||
""" return if I have any nans; enables various perf speedups """ | |||
return self._isnan.any() | |||
|
|||
def _maybe_mask_results(self, result, fill_value=None, convert=None): | |||
def _maybe_mask_results(self, result, fill_value=iNaT, convert=None): | |||
""" | |||
Parameters | |||
---------- |
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 update the doc-string for fill_value
pandas/core/arrays/period.py
Outdated
# delta_to_nanoseconds(delta). Because delta here is an integer, | ||
# delta_to_nanoseconds will return it unchanged. | ||
result = super(PeriodArray, self)._add_delta_td(other.n) | ||
return type(self)(result, freq=self.freq) | ||
|
||
def _add_delta_td(self, other): |
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 rename this to _add_timedelta? (or _add_delta_timedelta)
Ping |
thanks @jbrockmendel |
…y_tests * repo_org/master: (52 commits) ENH: Allow rename_axis to specify index and columns arguments (pandas-dev#20046) STY: proposed isort settings [ci skip] [skip ci] [ciskip] [skipci] (pandas-dev#23366) MAINT: Remove extraneous test.parquet file CLN: Follow-up comments to pandas-devgh-23392 (pandas-dev#23401) BUG GH23282 calling min on series of NaT returns NaT (pandas-dev#23289) unpin openpyxl (pandas-dev#23361) REF: collect ops dispatch functions in one place, try to de-duplicate SparseDataFrame methods (pandas-dev#23060) CLN: Remove pandas.tools module (pandas-dev#23376) CLN: Remove some dtype methods from API (pandas-dev#23390) CLN: Cleanup toplevel namespace shims (pandas-dev#23386) DOC: fixup whatsnew note for GH21394 (pandas-dev#23355) Fix import format at pandas/tests/extension directory (pandas-dev#23365) DOC: Remove Series.sortlevel from api.rst (pandas-dev#23395) API: Disallow dtypes w/o frequency when casting (pandas-dev#23392) BUG/TST/REF: Datetimelike Arithmetic Methods (pandas-dev#23215) STYLE: lint add np.nan* funcs to cython_table (pandas-dev#22109) Run Isort on tests/util single PR (pandas-dev#23347) BUG: Fix date_range overflow (pandas-dev#23345) Run Isort on tests/arrays single PR (pandas-dev#23346) ...
@TomAugspurger @jorisvandenbossche @jreback as discussed
git diff upstream/master -u -- "*.py" | flake8 --diff