Skip to content

BUG: fix inserting tz-aware datetime to Series, closes #12862 #27322

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 9 commits into from
Jul 11, 2019

Conversation

jbrockmendel
Copy link
Member

@@ -523,7 +523,22 @@ def test_setitem_with_tz_dst():
tm.assert_series_equal(s, exp)


def test_categorial_assigning_ops():
def test_setitem_new_key_tz():
Copy link
Contributor

Choose a reason for hiding this comment

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

there is a file for timezones and timeseries tests under indexing

prefer one of those

Copy link
Member Author

Choose a reason for hiding this comment

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

sure. for next time, when does a test go in tests.indexing vs tests.series.indexing vs tests.frame.test_indexing?

Copy link
Member Author

Choose a reason for hiding this comment

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

both tests.series.indexing.test_datetime and tests.indexing.test_datetime are about objects with DatetimeIndex, not datetime values

Copy link
Contributor

Choose a reason for hiding this comment

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

well test_indexing is really big, just like to split out when dealing with specific types (may not be perfect but that's the idea); this should clearly be there.

Copy link
Member Author

Choose a reason for hiding this comment

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

i think figuring this out merits a dedicated pass(es) similar to tests.arithmetic and tests.reductions

Copy link
Contributor

Choose a reason for hiding this comment

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

see my comment below, I am sure we test this for .loc, so this belongs with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Do you have a suggestion as to where that might be? I'm not eager to manually sort through 50k+ tests. (and there aren't any foo.loc setitem calls in either tests.series.test_timezones or tests.series.test_timeseries)

Copy link
Contributor

Choose a reason for hiding this comment

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

test_loc_coerceion in pandas/tests/indexing/test_loc.py

Copy link
Member Author

Choose a reason for hiding this comment

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

everything in that file is testing loc. you want to mix non-loc tests in with that?

Copy link
Member Author

Choose a reason for hiding this comment

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

moved

@@ -1230,6 +1230,13 @@ def setitem(key, value):
if _is_unorderable_exception(e):
raise IndexError(key)

if is_scalar(key) and not is_integer(key) and key not in self.index:
Copy link
Contributor

Choose a reason for hiding this comment

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

i would trace further

you are adding a new case whereby it’s likely an existing path is just incorrect somewhere

Copy link
Member Author

Choose a reason for hiding this comment

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

the path here is above when we call self._set_with_engine(key, value), _set_with_engine calls self.index._engine.set_value(self._values, key, value). The engine expects self._values to be an ndarray, but here it is a DatetimeArray. Eventually it might be worth addressing this at the low-level engine level, but definitely out of scope for now.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, that's where I got stuck trying to fix this same bug. I tried converting it to an ndarray before passing it into the engine but a lot of other routines failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

move this to _set_with and its better (after the cases are narrowed down)

Copy link
Member Author

Choose a reason for hiding this comment

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

sure

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype labels Jul 10, 2019
pd.to_datetime(42).tz_localize("UTC"),
pd.to_datetime(666).tz_localize("UTC"),
]

Copy link
Contributor

Choose a reason for hiding this comment

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

can you also test using .loc which give the same result

Copy link
Contributor

Choose a reason for hiding this comment

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

we may actually have a test for this already (so good to combine)

@@ -1230,6 +1230,13 @@ def setitem(key, value):
if _is_unorderable_exception(e):
raise IndexError(key)

if is_scalar(key) and not is_integer(key) and key not in self.index:
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to _set_with and its better (after the cases are narrowed down)

@@ -523,7 +523,22 @@ def test_setitem_with_tz_dst():
tm.assert_series_equal(s, exp)


def test_categorial_assigning_ops():
def test_setitem_new_key_tz():
Copy link
Contributor

Choose a reason for hiding this comment

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

test_loc_coerceion in pandas/tests/indexing/test_loc.py

@jbrockmendel
Copy link
Member Author

comments addressed i think

@jreback jreback added this to the 0.25.0 milestone Jul 11, 2019
@jreback jreback merged commit 0cefff0 into pandas-dev:master Jul 11, 2019
@jreback
Copy link
Contributor

jreback commented Jul 11, 2019

ok thanks; this looks better.

@jbrockmendel jbrockmendel deleted the fix12862 branch July 11, 2019 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.__setitem__ with datetime64[ns, tz] dtype raises ValueError when setting a tz-aware timestamps
3 participants