-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
[Bug] Comparison between two PeriodIndexes doesn't validate length (GH #23078) #23896
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
|
Hello @makbigc! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on December 25, 2018 at 11:36 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #23896 +/- ##
==========================================
+ Coverage 92.3% 92.31% +<.01%
==========================================
Files 163 163
Lines 51950 51954 +4
==========================================
+ Hits 47953 47961 +8
+ Misses 3997 3993 -4
Continue to review full report at Codecov.
|
jreback
left a comment
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.
let's make this a general check in the base class instead
pandas/core/arrays/period.py
Outdated
| msg = DIFFERENT_FREQ_INDEX.format(self.freqstr, other.freqstr) | ||
| raise IncompatibleFrequency(msg) | ||
|
|
||
| if other.ndim > 0 and len(self) != len(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 should fail if ndim of other != 1
we don't generally check this for other arrays (though we should). So I would maybe add this check on the base array class and just call it here, _validate_equal(self, other) or something
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.
By base class, do you mean ExtensionOpsMixin?
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.
And I would call it something like _validate_shape or _check_shape.
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.
yes, I think we have an implicit guarantee on 1-D ness now (or at the very least the pandas extension types do).
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.
Related #23853
|
@makbigc can you merge master and update |
9b0b723 to
47bf1bf
Compare
|
this overlaps with #24397 @jbrockmendel can you comment here |
| def test_error(self): | ||
| pass | ||
|
|
||
| def test_arith_diff_lengths(self): |
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.
are these tests passed because they would fail? if so, mark with @pytest.mark.xfail.
|
|
||
| def test_arith_diff_lengths(self, data, all_arithmetic_operators): | ||
| op = self.get_op_from_name(all_arithmetic_operators) | ||
| other = data[:3] |
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 test actually wouldn't catch the behavior in #23078, which is caused specifically by comparisons of PeriodIndex with length-1 objects.
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 issue in #23078 was treated in the function test_comp_op (pandas/tests/indexes/period/test_period.py).
4d2ea4e to
ac94453
Compare
jreback
left a comment
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.
why are you adding tests to each of the EA subclasses? the base test should work for each of these.
| - Bug in :class:`DatetimeIndex` and :class:`TimedeltaIndex` where indexing with ``Ellipsis`` would incorrectly lose the index's ``freq`` attribute (:issue:`21282`) | ||
| - Clarified error message produced when passing an incorrect ``freq`` argument to :class:`DatetimeIndex` with ``NaT`` as the first entry in the passed data (:issue:`11587`) | ||
| - Bug in :func:`to_datetime` where ``box`` and ``utc`` arguments were ignored when passing a :class:`DataFrame` or ``dict`` of unit mappings (:issue:`23760`) | ||
| - Bug in :class:`PeriodIndex` when comparing indexes of different lengths, ValueError is not raised (:issue:`23078`) |
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.
use double backticks around ValueError
| def test_arith_diff_lengths(self, data, all_arithmetic_operators): | ||
| op = self.get_op_from_name(all_arithmetic_operators) | ||
| other = data[:3] | ||
| with pytest.raises(ValueError): |
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 match the message as well
| def test_compare_diff_lengths(self, data, all_compare_operators): | ||
| op = self.get_op_from_name(all_compare_operators) | ||
| other = data[:3] | ||
| with pytest.raises(ValueError): |
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.
match the message
| for i in alter] | ||
| self._compare_other(s, data, op_name, other) | ||
|
|
||
| # TODO: |
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.
why are these xfail? make the change as needed in the decimal code
| s, op, other, exc=TypeError | ||
| ) | ||
|
|
||
| def test_arith_diff_lengths(self): |
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.
why are these added?
|
Should I close this PR? Because #23078 was already resolved by #24397. The length check is done in the wrapper of _period_array_cmp. This is not need to add _validate_shape additionally. The generic base test cannot handle all six EA subclasses:
The raise of ValueError for DecimalArray could be implemented in a new PR. |
git diff upstream/master -u -- "*.py" | flake8 --diff