-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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: pd.Series.replace does not preserve the original dtype #33622
BUG: pd.Series.replace does not preserve the original dtype #33622
Conversation
5f11fc1
to
cc56667
Compare
cc56667
to
9ef9f9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kotamatsuoka
Minor comments ahead of core-members' reviews
pandas/core/internals/blocks.py
Outdated
dtype, _ = infer_dtype_from(other, pandas_dtype=True) | ||
if isinstance(other, str): | ||
dtype = "string" | ||
if is_dtype_equal(self.dtype, dtype): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't hard-code things like this, instead you can try to teach infer_dtype_from to do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry...I removed hard-code.
79ad94f
to
7cbf0ea
Compare
7cbf0ea
to
078aca1
Compare
pandas/core/internals/blocks.py
Outdated
dtype = np.object_ | ||
else: | ||
# if we cannot then coerce to object | ||
dtype, _ = infer_dtype_from(other, pandas_dtype=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to move into infer_dtype_from(), but a lot of tests fail. So, I didn't move.
41fb227
to
c9f6d50
Compare
Hello @kotamatsuoka! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-06-06 10:18:53 UTC |
c9f6d50
to
571ab8a
Compare
6b2f09c
to
0d244c2
Compare
0d244c2
to
b227024
Compare
2844c80
to
38a5c83
Compare
38a5c83
to
a62c896
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also needs a whatsnew note, EA section, bug fixes for 1.1
pandas/core/internals/blocks.py
Outdated
if self.is_bool or is_object_dtype(dtype) or is_bool_dtype(dtype): | ||
if ( | ||
is_extension_array_dtype(self.dtype) | ||
and not is_categorical_dtype(self.dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just use is_extension_array_dtype here
[ | ||
( | ||
pd.Series(["one", "two"], dtype="string"), | ||
{"one": "1", "two": "2"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a bunch more tests which can hit the other EA types, e.g. Intervval, Period, Datetime w/tz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added test cases.
6e507a4
to
aa2f973
Compare
918b4e2
to
a933ad8
Compare
a933ad8
to
b777345
Compare
Hi @kotamatsuoka - is this still active? Looks like there's some test failures and linting errors (from |
@kotamatsuoka closing as stale. please comment if you want to continue and the PR will be reopened. |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff