|
10 | 10 | from numpy.random import randn
|
11 | 11 |
|
12 | 12 | import numpy as np
|
13 |
| - |
14 | 13 | from pandas.core.api import DataFrame, Panel
|
15 | 14 | from pandas.core.computation import expressions as expr
|
16 | 15 | from pandas import compat, _np_version_under1p11, _np_version_under1p13
|
|
37 | 36 | _integer2 = DataFrame(np.random.randint(1, 100, size=(101, 4)),
|
38 | 37 | columns=list('ABCD'), dtype='int64')
|
39 | 38 |
|
| 39 | + |
40 | 40 | with catch_warnings(record=True):
|
41 | 41 | _frame_panel = Panel(dict(ItemA=_frame.copy(),
|
42 | 42 | ItemB=(_frame.copy() + 3),
|
@@ -442,3 +442,19 @@ def test_bool_ops_warn_on_arithmetic(self):
|
442 | 442 | r = f(df, True)
|
443 | 443 | e = fe(df, True)
|
444 | 444 | tm.assert_frame_equal(r, e)
|
| 445 | + |
| 446 | + def test_bool_ops_column_name_dtype(self): |
| 447 | + # GH 22383 - .ne fails if columns containing column name 'dtype' |
| 448 | + df_has_error = DataFrame([[0, 1, 2, 'aa'], [0, 1, 2, 'aa'], |
| 449 | + [0, 1, 5, 'bb'], [0, 1, 5, 'bb'], |
| 450 | + [0, 1, 5, 'bb'], ['cc', 4, 4, 4]], |
| 451 | + columns=['a', 'b', 'c', 'dtype']) |
| 452 | + df = DataFrame([[0, 1, 2, 'aa'], [0, 1, 2, 'aa'], |
| 453 | + [0, 1, 5, 'bb'], [0, 1, 5, 'bb'], |
| 454 | + [0, 1, 5, 'bb'], ['cc', 4, 4, 4]], |
| 455 | + columns=['a', 'b', 'c', 'd']) |
| 456 | + result = df_has_error.loc[:, ['a', 'dtype']].ne(df_has_error.loc[:, |
| 457 | + ['a', 'dtype']]) |
| 458 | + assert_frame_equal(result, |
| 459 | + df.loc[:, ['a', 'd']].ne(df.loc[:, ['a', 'd']]). |
| 460 | + rename({'d': 'dtype'}, axis=1)) |
0 commit comments