Skip to content

ENH: Add warning when setting into nonexistent attribute #16951

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

Merged
merged 22 commits into from
Aug 7, 2017
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b5dde1e
ENH: adds warning when setting list-like into attribute
deniederhut Jul 15, 2017
4d3f87d
TST: Adds tests for warning behavior on set on nonexistent attr
deniederhut Jul 15, 2017
fb29857
DOC: replaces silent error for setattr on nonexistent name with UserW…
deniederhut Jul 15, 2017
af5ab38
CLN: juggles doc url to fit within 80 char per line
deniederhut Jul 15, 2017
f485e77
BUG: replaces single backticks with double backticks for rst
deniederhut Jul 15, 2017
bfb9f93
BUG: adds stacklevel to warning call
deniederhut Jul 15, 2017
61eca9d
DOC: adds 0.21.0 for appearance of setting warnings
deniederhut Jul 15, 2017
15ebdbc
ENH: Add warning when colname collides with methods
deniederhut Jul 15, 2017
30d98de
TST: Adds testing around warnings for setting attributes
deniederhut Jul 15, 2017
8d38f68
CLN: reformatting and cleanup of setting tests
deniederhut Jul 15, 2017
c9c43db
ENH: Clarifies wording of warning message for column name collision
deniederhut Jul 15, 2017
0a25a56
BUG: coerces _set_item key to a string
deniederhut Jul 15, 2017
150d586
FIX: only warn getattr when key is str
deniederhut Jul 19, 2017
02cb426
TST: adds comments about tests which should not warn
deniederhut Jul 19, 2017
562c164
DOC: adds column/attribute warnings to whatsnew
deniederhut Jul 19, 2017
f3fdd19
DOC: moves examples from whatsnew to indexing
deniederhut Jul 19, 2017
c6fe062
FIX: replaces ndim check with ABC subclass check
deniederhut Jul 19, 2017
8ad4d05
CLN: breaks line to avoid 81 char length
deniederhut Jul 23, 2017
e5cc166
TST: renames 'bool' columns in pytables test to avoid collision warning
deniederhut Jul 24, 2017
e02244d
BUG: fixes 'string_types' encoding failure with unicode cols in py2
deniederhut Jul 27, 2017
d38ecca
BUG: fixes reversion of isnull/isna produced in merge
deniederhut Jul 29, 2017
b86546e
DOC: fixes references in indexing and whatsnew
deniederhut Aug 4, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: Adds tests for warning behavior on set on nonexistent attr
  • Loading branch information
deniederhut committed Aug 4, 2017
commit 4d3f87d13e144a615ab46f1e1883a4b3a96524bc
7 changes: 7 additions & 0 deletions pandas/tests/dtypes/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
import pandas as pd
from pandas.core.dtypes import generic as gt
import pytest


class TestABCClasses(object):
Expand All @@ -17,6 +18,7 @@ class TestABCClasses(object):
df = pd.DataFrame({'names': ['a', 'b', 'c']}, index=multi_index)
sparse_series = pd.Series([1, 2, 3]).to_sparse()
sparse_array = pd.SparseArray(np.random.randn(10))
series = pd.Series([1, 2, 3])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u can remove this


def test_abc_types(self):
assert isinstance(pd.Index(['a', 'b', 'c']), gt.ABCIndex)
Expand All @@ -38,3 +40,8 @@ def test_abc_types(self):
assert isinstance(self.sparse_array, gt.ABCSparseArray)
assert isinstance(self.categorical, gt.ABCCategorical)
assert isinstance(pd.Period('2012', freq='A-DEC'), gt.ABCPeriod)
with catch_warnings(record=True) as w:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are you testing here?

self.series.not_an_index = [1, 2]
assert len(w) == 0 # fail if false warning on Series
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to a new test add the issue number as a comment

with pytest.warns(UserWarning):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use tm.assert_raises_warning

self.df.not_a_column = [1, 2]