-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Fix DatetimeIndex.insert() with strings. #5819
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
BUG: Fix DatetimeIndex.insert() with strings. #5819
Conversation
This fails tests because of restrictions on partial setting from #4940. I'm not actually convinced that the tests are correct (or at the very least the issue needs to be handled elsewhere). I'll circle back to this tomorrow. This PR makes In [2]: ind = pd.Index(range(10))
In [3]: ind.insert(3, '5')
Out[3]: Index([0, 1, 2, u'5', 3, 4, 5, 6, 7, 8, 9], dtype='object') I'm not clear on why partial setting that has incompatible dtype labels is actually wrong, especially because you can currently do it with non-DatetimeIndex: In [4]: df = pd.DataFrame(range(10))
In [5]: df
Out[5]:
0
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
[10 rows x 1 columns]
In [6]: df.loc['apple', :] = 2
In [7]: df
Out[7]:
0
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
apple 2
[11 rows x 1 columns] |
You could end up with something similar by concatenating DataFrames with different Index dtypes or by doing a join, so not sure it really makes sense to block partial setting via loc/ix. |
Just to summarize @jreback 's resolution for those who don't want to follow the link:
|
@jtratner just need a release note....then go ahead and merge..thxs |
Coerces to object Index instead.
@jtratner this looked fine...thought it was merged... can you rebase and merge it? |
Falls back to object Index instead. (previously wasn't checking for them), but only strings are allowed.
Fixes #5818.