BUG: keep value types when calling .items() on Series #50147
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have identified that the
.items()
method ofSeries
modifies the type of values, before returning them.One of the major consequences (for me) is that the
.to_dict()
method unexpectedly returns modified types.This can be problematic with
float32
orfloat16
types, as.items()
would convert them to Python's float, thus changing the actual value of the output by adding some extra decimal digits..items()
modifies the type because it calls the.__iter__()
method of the parent's classbase.IndexOpsMixin
, which enforces the return of Python types.From my point,
.items()
and.to_dict()
should not change the type of the values. This can be easily done by refering toSeries._values
, as proposed in this PR.