pydata/pandas — pull request #6767 by sinhrks (2014-04-02 14:58:15+00:00)
Title: ENH: rename function now has errors keyword

Same background as #6736.

Currently,
- When a function is passed, any error caused by the function results in `rename` error.
- When a dict is passed, label which is not included in the axis will be silently skipped. Even though `drop` raises `ValueError` in such a case.

```
>>> df = pd.DataFrame({1: [1, 2], 'B': pd.to_datetime(['2010-01-01', np.nan])})
>>> renamed_func = df.rename(columns=lambda x: x + 1)
TypeError: cannot concatenate 'str' and 'int' objects

>>> renamed_dict = df.rename(columns={'B':'C', 'D':'E'})
Index([1, u'C'], dtype='object')
```

I think it is nice if `rename` also has `errors` keyword to:
- Suppress error raised by the function and `rename` only non-problematic labels (`errors='ignore'`), or raise error whatever derived from the function (`errors='raise'`).
- Suppress error if label is not found in the target axis, and `rename` only non-problematic labels (`errors='ignore'`), or raise error if any of label is not included in the target axis (`errors='raise'`).

I feel the default should be `errors='raise'` in the future version based on the other functions behavior. This doesn't affect to the current behavior when a function is passed, but affects to when a dict is passed.

In this version, `rename` raise `FutureWarning` for future precaution if it is called with non-existing label. And it is possible to force `rename` to raise `ValueError` in such a case by specifying `errors='raise'`.

```
>>> renamed_func = df.rename(columns=lambda x: x + 1, errors='ignore')
Index([2, u'B'], dtype='object')
>>> renamed_dict = df.rename(columns={'B':'C', 'D':'E', 'F':'G'}, errors='ignore')
Index([1, u'C'], dtype='object')
```