This repository was archived by the owner on Apr 10, 2024. It is now read-only.
This repository was archived by the owner on Apr 10, 2024. It is now read-only.
Revisit Series implicit size mutability and implicit type conversions #32
Open
Description
I haven't been able to wrap my head around these behaviors:
In [10]: s = pd.Series()
In [11]: s['a'] = 7
In [12]: s
Out[12]:
a 7
dtype: int64
or
In [2]: s = pd.Series([1, 2, 3])
In [3]: s['4'] = 'b'
In [4]: s
Out[4]:
0 1
1 2
2 3
4 b
dtype: object
On first principles, I think these should raise KeyError and ValueError/TypeError, respectively. I'm concerned that preserving these APIs (especially implicit type changes) is going to be problematic for pandas 2.0 if our goal is to provide more precise / consistent / explicit behavior, particularly with respect to data types. If you want to change the type of something, you should cast (unless there is a standard implicit cast, e.g. int -> float in arithmetic). In the case of implicit size mutation, it seems like a recipe for bugs to me (or simply working around coding anti-patterns -- better to explicitly reindex then assign values).
Let me know other thoughts about this.