Skip to content

Asobject tz #1383

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

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 6 additions & 2 deletions doc/source/whatsnew/v0.8.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ clear of NumPy 1.6's datetime64 API functions (though limited as they are) and
only interact with this data using the interface that pandas provides.

Bug fixes to the 0.7.x series for legacy NumPy < 1.6 users will be provided as
they arise. There will be no more further development in 1.7.x beyond bug
they arise. There will be no more further development in 0.7.x beyond bug
fixes.

Time series changes and improvements
Expand All @@ -39,6 +39,10 @@ Time series changes and improvements
With this release, legacy scikits.timeseries users should be able to port
their code to use pandas.

.. note::

See :ref:`documentation <timeseries>` for overview of pandas timeseries API.

- New datetime64 representation **speeds up join operations and data
alignment**, **reduces memory usage**, and improve serialization /
deserialization performance significantly over datetime.datetime
Expand Down Expand Up @@ -133,7 +137,7 @@ Other new features
- Add max_colwidth configuration option for DataFrame console output
- Interpolate Series values using index values
- Can select multiple columns from GroupBy
- Add Series/DataFrame.update methods for updating values in place
- Add Series/DataFrame.:ref:`update <merging.combine_first.update>` methods for updating values in place

Other API changes
~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 5 additions & 3 deletions pandas/tseries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ def __new__(cls, data=None,
# Convert local to UTC
ints = subarr.view('i8')
lib.tz_localize_check(ints, tz)
subarr = lib.tz_convert(ints, tz, _utc())
subarr = lib.tz_convert(ints, tz, getattr(data, 'tz', _utc()))
subarr = subarr.view('M8[ns]')

subarr = subarr.view(cls)
subarr.name = name
subarr.offset = offset
subarr.tz = tz
subarr.tz = getattr(data, 'tz', tz)

if verify_integrity and len(subarr) > 0:
if offset is not None and not infer_freq:
Expand Down Expand Up @@ -540,7 +540,9 @@ def asobject(self):

def _get_object_index(self):
boxed_values = _dt_box_array(self.asi8, self.offset, self.tz)
return Index(boxed_values, dtype=object)
idx = Index(boxed_values, dtype=object)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't actually what I meant in #1345, only to test that the Timestamp or datetime.datetime values in the resulting object arrays have the right tzinfo set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isn't that already in test_timezones.test_asobject_tz_box?

On Sun, Jun 3, 2012 at 1:17 PM, Wes McKinney <
[email protected]

wrote:

@@ -540,7 +540,9 @@ def asobject(self):

 def _get_object_index(self):
     boxed_values = _dt_box_array(self.asi8, self.offset, self.tz)
  •    return Index(boxed_values, dtype=object)
    
  •    idx = Index(boxed_values, dtype=object)
    

This isn't actually what I meant in #1345, only to test that the Timestamp
or datetime.datetime values in the resulting object arrays have the right
tzinfo set


Reply to this email directly or view it on GitHub:
https://github.com/pydata/pandas/pull/1383/files#r919922

Chang She
Lambda Foundry http://www.lambdafoundry.com

Copy link
Member

Choose a reason for hiding this comment

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

Ah, hmm. good point. asobject_tz_box is actually not doing the right thing (and it disturbs me that the test passes). The issue is that there is a base time zone object that is obtained from pytz.timezone and Timestamps actually receive one of its tzinfos:

In [4]: tz._tzinfos
Out[4]: 
{(datetime.timedelta(-1, 68400),
  datetime.timedelta(0),
  'EST'): <DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD>,
 (datetime.timedelta(-1, 72000),
  datetime.timedelta(0, 3600),
  'EDT'): <DstTzInfo 'US/Eastern' EDT-1 day, 20:00:00 DST>,
 (datetime.timedelta(-1, 72000),
  datetime.timedelta(0, 3600),
  'EPT'): <DstTzInfo 'US/Eastern' EPT-1 day, 20:00:00 DST>,
 (datetime.timedelta(-1, 72000),
  datetime.timedelta(0, 3600),
  'EWT'): <DstTzInfo 'US/Eastern' EWT-1 day, 20:00:00 DST>}

In [5]: type(tz)
Out[5]: pytz.tzfile.US/Eastern

So the fact that that unit test passes is an accident. i'll remove it

Copy link
Member

Choose a reason for hiding this comment

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

Further:

In [2]: rng
Out[2]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2010-02-13 00:00:00, ..., 2010-05-06 00:00:00]
Length: 83, Freq: D, Timezone: US/Eastern

In [3]: rng[0]
Out[3]: Timestamp(2010, 2, 13, 0, 0, tzinfo=<DstTzInfo 'US/Eastern' EST-1 day, 19:00:00 STD>)

In [4]: rng[-1]
Out[4]: Timestamp(2010, 5, 6, 0, 0, tzinfo=<DstTzInfo 'US/Eastern' EDT-1 day, 20:00:00 DST>)

In [5]: rng[0].tz == rng[-1].tz
Out[5]: False

idx.tz = self.tz
return idx

def to_period(self, freq=None):
"""
Expand Down
8 changes: 8 additions & 0 deletions pandas/tseries/tests/test_timezones.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ def test_asobject_tz_box(self):
result = index.asobject
self.assert_(result[0].tz is tz)

def test_asobject_tz(self):
tz = pytz.timezone('US/Eastern')
index = DatetimeIndex(start='1/1/2005', periods=10, tz=tz,
freq='B')

result = DatetimeIndex(index.asobject)
self.assert_(result.tz is tz)

def test_tz_string(self):
result = date_range('1/1/2000', periods=10, tz='US/Eastern')
expected = date_range('1/1/2000', periods=10,
Expand Down