Commit 0b02747
committed
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 JanSchulz1 parent d876a9f commit 0b02747
File tree
6 files changed
+28
-19
lines changed- doc/source/whatsnew
- pandas
- core
- tests
6 files changed
+28
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
82 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2521 | 2521 | | |
2522 | 2522 | | |
2523 | 2523 | | |
2524 | | - | |
2525 | | - | |
| 2524 | + | |
| 2525 | + | |
| 2526 | + | |
2526 | 2527 | | |
2527 | 2528 | | |
2528 | 2529 | | |
| |||
2533 | 2534 | | |
2534 | 2535 | | |
2535 | 2536 | | |
2536 | | - | |
2537 | | - | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
2538 | 2540 | | |
2539 | 2541 | | |
2540 | 2542 | | |
| |||
2543 | 2545 | | |
2544 | 2546 | | |
2545 | 2547 | | |
2546 | | - | |
| 2548 | + | |
| 2549 | + | |
2547 | 2550 | | |
2548 | 2551 | | |
2549 | 2552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2631 | 2631 | | |
2632 | 2632 | | |
2633 | 2633 | | |
2634 | | - | |
2635 | | - | |
| 2634 | + | |
| 2635 | + | |
| 2636 | + | |
| 2637 | + | |
| 2638 | + | |
2636 | 2639 | | |
2637 | 2640 | | |
2638 | 2641 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | 107 | | |
114 | 108 | | |
115 | 109 | | |
| |||
240 | 234 | | |
241 | 235 | | |
242 | 236 | | |
243 | | - | |
244 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
245 | 244 | | |
246 | 245 | | |
247 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
| |||
0 commit comments