Skip to content

Commit

Permalink
WARN: add stacklevel to to_dict() UserWarning (pandas-dev#16927) (pan…
Browse files Browse the repository at this point in the history
…das-dev#16936)

* ERR: add stacklevel to to_dict() UserWarning (pandas-dev#16927)

* TST: Add warning testing to to_dict()

* Fix warning assertion on to_dict() test

* Add github issue to documentation on to_dict() warning test
  • Loading branch information
alanbato authored and 3553x committed Jul 16, 2017
1 parent 031cdaf commit f15394b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,8 @@ def to_dict(self, orient='dict', into=dict):
"""
if not self.columns.is_unique:
warnings.warn("DataFrame columns are not unique, some "
"columns will be omitted.", UserWarning)
"columns will be omitted.", UserWarning,
stacklevel=2)
# GH16122
into_c = standardize_mapping(into)
if orient.lower().startswith('d'):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_convert_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ def test_to_dict_errors(self, mapping):
with pytest.raises(TypeError):
df.to_dict(into=mapping)

def test_to_dict_not_unique_warning(self):
# GH16927: When converting to a dict, if a column has a non-unique name
# it will be dropped, throwing a warning.
df = DataFrame([[1, 2, 3]], columns=['a', 'a', 'b'])
with tm.assert_produces_warning(UserWarning):
df.to_dict()

@pytest.mark.parametrize('tz', ['UTC', 'GMT', 'US/Eastern'])
def test_to_records_datetimeindex_with_tz(self, tz):
# GH13937
Expand Down

0 comments on commit f15394b

Please sign in to comment.