-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Comparisons result in different dtypes for empty DataFrames #15077 #15115
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
Changes from 5 commits
ea11867
19296f1
28437bb
eb7d9fd
9723c5d
fcbcb5b
b2f2d1e
dc0803b
a5ca359
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -671,6 +671,28 @@ def _test_seq(df, idx_ser, col_ser): | |
exp = DataFrame({'col': [False, True, False]}) | ||
assert_frame_equal(result, exp) | ||
|
||
def test_return_dtypes_bool_op_costant(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you replicate these tests for series as well (or point to that we have equiv tests) |
||
# GH15077 | ||
df = DataFrame({'x': [1, 2, 3], 'y': [1., 2., 3.]}) | ||
const = 2 | ||
|
||
# not empty DataFrame | ||
for op in ['eq', 'ne', 'gt', 'lt', 'ge', 'le']: | ||
f = getattr(df, op) | ||
for col in ['x', 'y']: | ||
res = f(const) | ||
c = getattr(res, col) | ||
self.assertEqual(c.dtypes, bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
|
||
# empty DataFrame | ||
empty = df.iloc[:0] | ||
for op in ['eq', 'ne', 'gt', 'lt', 'ge', 'le']: | ||
f = getattr(empty, op) | ||
for col in ['x', 'y']: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of this comparison, use
|
||
res = f(const) | ||
c = getattr(res, col) | ||
self.assertEqual(c.dtypes, bool) | ||
|
||
def test_dti_tz_convert_to_utc(self): | ||
base = pd.DatetimeIndex(['2011-01-01', '2011-01-02', | ||
'2011-01-03'], tz='UTC') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1294,6 +1294,19 @@ def test_comparison_flex_alignment_fill(self): | |
exp = pd.Series([True, True, False, False], index=list('abcd')) | ||
assert_series_equal(left.gt(right, fill_value=0), exp) | ||
|
||
def test_return_dtypes_bool_op_costant(self): | ||
# gh15115 | ||
s = pd.Series([1, 3, 2], index=range(3)) | ||
for op in ['eq', 'ne', 'gt', 'lt', 'ge', 'le']: | ||
f = getattr(s, op) | ||
self.assertFalse(f(2).dtypes, np.dtype('bool')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same type of comparison here and below |
||
|
||
# empty Series | ||
empty = s.iloc[:0] | ||
for op in ['eq', 'ne', 'gt', 'lt', 'ge', 'le']: | ||
f = getattr(empty, op) | ||
self.assertFalse(f(2).dtypes, np.dtype('bool')) | ||
|
||
def test_operators_bitwise(self): | ||
# GH 9016: support bitwise op for integer types | ||
index = list('bca') | ||
|
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.
say
Incorrect dtyped Series was returned by comparions methods.........against a constant for an empty DataFrame
put Series/DataFrame with double-backticks.