-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Frame ops prelims - de-duplicate, remove unused kwargs #19522
Conversation
Codecov Report
@@ Coverage Diff @@
## master #19522 +/- ##
==========================================
- Coverage 91.6% 91.6% -0.01%
==========================================
Files 150 150
Lines 48750 48736 -14
==========================================
- Hits 44657 44644 -13
+ Misses 4093 4092 -1
Continue to review full report at Codecov.
|
pandas/core/frame.py
Outdated
fill_value=fill_value, | ||
try_cast=try_cast) | ||
else: | ||
if len(other) == 0: |
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.
not len
pandas/core/frame.py
Outdated
fill_value=None, try_cast=True): | ||
if len(other) == 0: | ||
return self * np.nan | ||
if len(self) == 0: |
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.
same
pandas/core/frame.py
Outdated
if len(other) == 0: | ||
return self * np.nan | ||
if len(self) == 0: | ||
# Ambiguous case, use _series so works with 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.
what is this 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.
Not totally sure. Possibly a holdover from higher-dim implementation?
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.
pandas/core/frame.py
Outdated
@@ -3960,52 +3959,40 @@ def f(i): | |||
|
|||
def _combine_series(self, other, func, fill_value=None, axis=None, | |||
level=None, try_cast=True): | |||
if fill_value is not None: | |||
raise NotImplementedError("fill_value %r not supported." % |
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.
is this hit in tests?
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 .format() here instead
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 to both. tests.frame.test_operators.TestDataFrameOperators.test_arith_flex_frame:
with tm.assert_raises_regex(NotImplementedError, 'fill_value'):
self.frame.add(self.frame.iloc[0], fill_value=3)
so you need some tests to validate your claims at the top of the PR
and a release note. |
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -581,6 +581,7 @@ Numeric | |||
- Bug in :class:`Index` multiplication and division methods where operating with a ``Series`` would return an ``Index`` object instead of a ``Series`` object (:issue:`19042`) | |||
- Bug in the :class:`DataFrame` constructor in which data containing very large positive or very large negative numbers was causing ``OverflowError`` (:issue:`18584`) | |||
- Bug in :class:`Index` constructor with ``dtype='uint64'`` where int-like floats were not coerced to :class:`UInt64Index` (:issue:`18400`) | |||
- Bug in :class:`DataFrame` flex arithmetic methods that failed to raise ``NotImplementedError` in cases where either argument has length zero (:issue:`19522`) |
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.
need double backticks on NotImplementedError. can you be slightly more descriptive here.
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.
a user is reading this and would want to know what if anything they need to change.
@@ -80,6 +80,26 @@ def _try_get_item(x): | |||
return x | |||
|
|||
|
|||
def _make_invalid_op(name): |
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.
consider moving this function to core/ops (and parameterizing so you can use it for index/series)
@@ -451,6 +451,18 @@ def test_arith_flex_frame(self): | |||
with tm.assert_raises_regex(NotImplementedError, 'fill_value'): | |||
self.frame.add(self.frame.iloc[0], axis='index', fill_value=3) | |||
|
|||
def test_arith_flex_zero_len_raises(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.
shouldn't these be in test_arithmetic?
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.
Eventually yes. The more important grouping for now is that this belongs with the test above it, which I plan to split/parametrize before moving to test_arithmetic
pandas/tests/frame/test_operators.py
Outdated
df.add(ser, fill_value='E') | ||
|
||
with tm.assert_raises_regex(NotImplementedError, 'fill_value'): | ||
ser.to_frame().sub(df[0], axis=None, fill_value=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.
just create the required frame here rather than using ser.to_frame()
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.
Sure.
pandas/tests/frame/test_operators.py
Outdated
df = pd.DataFrame([[1, 2], [3, 4]]) | ||
|
||
with tm.assert_raises_regex(NotImplementedError, 'fill_value'): | ||
df.add(ser, fill_value='E') |
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 raise ValueError, not NIE.
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 existing implementation raises NIE outside of these corner cases. For the time being I'm assuming there's a reason for that.
thanks |
Starting in on making DataFrame ops consistent with Series and Index ops. As a first pass, this goes through and removes some duplicate code and unused arguments.
Changes logic in exactly two corner cases: arithmetic operations
frame.op(series, axis=None, fill_value=not_none)
where one ofseries
orframe
has length zero.axis
needs to be specifically passed asNone
to hit the changed case.will now raise instead of returning