Skip to content

Commit f680ca6

Browse files
committed
add test and what's new
1 parent f42bb7b commit f680ca6

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

doc/source/whatsnew/v0.24.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ Indexing
654654
- Fixed ``DataFrame[np.nan]`` when columns are non-unique (:issue:`21428`)
655655
- Bug when indexing :class:`DatetimeIndex` with nanosecond resolution dates and timezones (:issue:`11679`)
656656
- Bug where indexing with a Numpy array containing negative values would mutate the indexer (:issue:`21867`)
657+
- Bug Dataframe.ne fails if columns containing column name 'dtype'
658+
657659

658660
Missing
659661
^^^^^^^

pandas/tests/test_expressions.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from numpy.random import randn
1111

1212
import numpy as np
13-
1413
from pandas.core.api import DataFrame, Panel
1514
from pandas.core.computation import expressions as expr
1615
from pandas import compat, _np_version_under1p11, _np_version_under1p13
@@ -37,6 +36,7 @@
3736
_integer2 = DataFrame(np.random.randint(1, 100, size=(101, 4)),
3837
columns=list('ABCD'), dtype='int64')
3938

39+
4040
with catch_warnings(record=True):
4141
_frame_panel = Panel(dict(ItemA=_frame.copy(),
4242
ItemB=(_frame.copy() + 3),
@@ -442,3 +442,19 @@ def test_bool_ops_warn_on_arithmetic(self):
442442
r = f(df, True)
443443
e = fe(df, True)
444444
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

Comments
 (0)