Skip to content

Series with dtype=object does unexpected type conversion #39285

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

Merged
merged 10 commits into from
Jan 28, 2021
Merged

Series with dtype=object does unexpected type conversion #39285

merged 10 commits into from
Jan 28, 2021

Conversation

ftrihardjo
Copy link
Contributor

@ftrihardjo ftrihardjo commented Jan 20, 2021

@pep8speaks
Copy link

pep8speaks commented Jan 20, 2021

Hello @ftrihardjo! 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 2021-01-28 09:55:31 UTC

@jreback jreback changed the title pandas-dev issue #21881 Series with dtype=object does unexpected type conversion Jan 20, 2021
@jreback jreback added Dtype Conversions Unexpected or buggy dtype conversions Testing pandas testing functions or related to the test suite labels Jan 20, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls follow the precommit instructions to lint your code

@@ -167,3 +167,15 @@ def test_attrs(self):
s.attrs["version"] = 1
result = s + 1
assert result.attrs == {"version": 1}

def test_series_with_object_dtype(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should go in pandas/tests/series/indexing/test_setitem.py

name the test with _empty in its name

series = pd.Series([], dtype=object)
series["timestamp"] = timestamp
expected = type(series.timestamp)
series = pd.Series([], dtype=object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line between cases

timestamp = pd.Timestamp(1412526600000000000)
series = pd.Series([], dtype=object)
series["timestamp"] = timestamp
expected = type(series.timestamp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explcity construct the result series and use tm.assert_series_equal

@ftrihardjo ftrihardjo requested a review from jreback January 27, 2021 01:03
series["anything"] = 300.0
series["timestamp"] = timestamp
result = series["timestamp"]
assert isinstance(result, Timestamp) and isinstance(expected, Timestamp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can
assert result == expected

@jreback jreback added this to the 1.3 milestone Jan 28, 2021
@jreback jreback merged commit 179fe3a into pandas-dev:master Jan 28, 2021
@jreback
Copy link
Contributor

jreback commented Jan 28, 2021

thanks @ftrihardjo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dtype Conversions Unexpected or buggy dtype conversions Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series with dtype=object does unexpected type conversion
3 participants