Skip to content

BUG: inconcistency in contained values of a Series created from a DatetimeIndex with a tz #6419

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 1 commit into from
Feb 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,17 +2097,23 @@ def test_set_index_cast_datetimeindex(self):
i = pd.DatetimeIndex(pd.tseries.tools.to_datetime(['2013-1-1 13:00','2013-1-2 14:00'], errors="raise")).tz_localize('US/Pacific')
df = DataFrame(np.random.randn(2,1),columns=['A'])

expected = Series(i)
self.assertTrue(expected.dtype == object)
self.assertTrue(i.equals(expected.values.values))
expected = Series(np.array([pd.Timestamp('2013-01-01 13:00:00-0800', tz='US/Pacific'),
pd.Timestamp('2013-01-02 14:00:00-0800', tz='US/Pacific')], dtype="object"))

# convert index to series
result = Series(i)
assert_series_equal(result, expected)

# assignt to frame
df['B'] = i
result = df['B']
assert_series_equal(result, expected)

# keep the timezone
result = i.to_series(keep_tz=True)
assert_series_equal(result.reset_index(drop=True), expected)

# convert to utc
df['C'] = i.to_series().reset_index(drop=True)
result = df['C']
comp = DatetimeIndex(expected.values).copy()
Expand Down
2 changes: 1 addition & 1 deletion pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def to_series(self, keep_tz=False):
def _to_embed(self, keep_tz=False):
""" return an array repr of this object, potentially casting to object """
if keep_tz and self.tz is not None and str(self.tz) != 'UTC':
return self.asobject
return self.asobject.values
return self.values

@property
Expand Down