ENH: improved dtype inference for Index.map by jbrockmendel · Pull Request #44609 · pandas-dev/pandas (original) (raw)
An example to illustrate, assume we have an uint32 index:
In [1]: idx = pd.NumericIndex([1, 2, 3], dtype="uint32")
In [2]: idx
Out[2]: NumericIndex([1, 2, 3], dtype='uint32')
In [3]: idx.map(lambda x: x)
Out[3]: NumericIndex([1, 2, 3], dtype='int64')
On master we always get an int64 index back, while with this PR it tries to preserve the original dtype:
In [3]: idx.map(lambda x: x)
Out[3]: NumericIndex([1, 2, 3], dtype='uint32')
Now, I don't know if this is actually a user visible change compared to the released version, since the above example is with a non-int64 dtype, which is only in master (so in that sense you could see it as a bug fix in the new not-yet-released feature)