You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BUG/API: Accessors like .cat raise AttributeError when invalid
`AttributeError` is really the appropriate error to raise for an invalid
attribute. In particular, it is necessary to ensure that tests like
`hasattr(s, 'cat')` work consistently on Python 2 and 3: on Python 2,
`hasattr(s, 'cat')` will return `False` even if a `TypeError` was raised, but
Python 3 more strictly requires `AttributeError`.
This is an unfortunate trap that we should avoid. See this discussion in
Seaborn for a full report:
mwaskom/seaborn#361 (comment)
Note that technically, this is an API change, since these accessors (all but
`.str`, I think) raised TypeError in the last release.
This also suggests another possibility for testing for Series with a
Categorical dtype (GH8814): just use `hasattr(s, 'cat')` (at least for Python
2 or pandas >=0.16).
CC mwaskom jorisvandenbossche JanSchulz
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v0.16.0.txt
+1
Original file line number
Diff line number
Diff line change
@@ -245,6 +245,7 @@ Backwards incompatible API changes
245
245
246
246
- Bar and horizontal bar plots no longer add a dashed line along the info axis. The prior style can be achieved with matplotlib's ``axhline`` or ``axvline`` methods (:issue:`9088`).
247
247
248
+
- ``Series`` accessors ``.dt``, ``.cat`` and ``.str`` now raise ``AttributeError`` instead of ``TypeError`` if the series does not contain the appropriate type of data (:issue:`9617`). This follows Python's built-in exception hierarchy more closely and ensures that tests like ``hasattr(s, 'cat')`` are consistent on both Python 2 and 3.
248
249
249
250
- ``Series`` now supports bitwise operation for integral types (:issue:`9016`)
0 commit comments