Skip to content
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

One more "'tzoffset' object has no attribute 'zone' " #1928

Closed
bf0 opened this issue Sep 18, 2012 · 2 comments
Closed

One more "'tzoffset' object has no attribute 'zone' " #1928

bf0 opened this issue Sep 18, 2012 · 2 comments
Labels
Bug Datetime Datetime data dtype
Milestone

Comments

@bf0
Copy link

bf0 commented Sep 18, 2012

Version: 0.9.0.dev_de31cbe (py2.7-macosx-10.6-x86_64)

Related to #1922 (closed)

I could be the only dummy with this kind of data so I might be able to find a few more of these.
Although I think these are typical Postgres tz-aware timestamps.

Repro

from StringIO import StringIO
table="""ts, d1
2012-05-23 10:00:01.123000-07:00,  3.1459265
2012-05-23 10:00:02.456000-07:00,  2.7182818
"""
df = pd.read_table(StringIO(table), parse_dates=True, index_col='ts', sep=',')
df.resample('t')

Traceback

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-90-a0ce8072eb5a> in <module>()
----> 1 df.resample('t')

   pandas/core/generic.pyc in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, limit, base)
    187                               fill_method=fill_method, convention=convention,
    188                               limit=limit, base=base)
--> 189         return sampler.resample(self)
    190 
    191     def first(self, offset):

   pandas/tseries/resample.pyc in resample(self, obj)
     66 
     67         if isinstance(axis, DatetimeIndex):
---> 68             rs = self._resample_timestamps(obj)
     69         elif isinstance(axis, PeriodIndex):
     70             offset = to_offset(self.freq)

   pandas/tseries/resample.pyc in _resample_timestamps(self, obj)
    180         axlabels = obj._get_axis(self.axis)
    181 
--> 182         binner, grouper = self._get_time_grouper(obj)
    183 
    184         # Determine if we're downsampling

   pandas/tseries/resample.pyc in _get_time_grouper(self, obj)
     95 
     96         if self.kind is None or self.kind == 'timestamp':
---> 97             binner, bins, binlabels = self._get_time_bins(axis)
     98         else:
     99             binner, bins, binlabels = self._get_time_period_bins(axis)

   pandas/tseries/resample.pyc in _get_time_bins(self, axis)
    111         first, last = _get_range_edges(axis, self.freq, closed=self.closed,
    112                                        base=self.base)
--> 113         binner = labels = DatetimeIndex(freq=self.freq, start=first, end=last)
    114 
    115         # a little hack

   pandas/tseries/index.pyc in __new__(cls, data, freq, start, end, periods, copy, name, tz, verify_integrity, normalize, **kwds)
    175         if data is None:
    176             return cls._generate(start, end, periods, name, offset,
--> 177                                  tz=tz, normalize=normalize)
    178 
    179         if not isinstance(data, np.ndarray):

   pandas/tseries/index.pyc in _generate(cls, start, end, periods, name, offset, tz, normalize)
    282             end = Timestamp(end)
    283 
--> 284         inferred_tz = tools._infer_tzinfo(start, end)
    285 
    286         if tz is not None and inferred_tz is not None:

   pandas/tseries/tools.pyc in _infer_tzinfo(start, end)
     31     tz = None
     32     if start is not None:
---> 33         tz = _infer(start, end)
     34     elif end is not None:
     35         tz = _infer(end, start)

   pandas/tseries/tools.pyc in _infer(a, b)
     27         tz = a.tzinfo
     28         if b and b.tzinfo:
---> 29             assert(tz.zone == b.tzinfo.zone)
     30         return tz
     31     tz = None

AttributeError: 'tzoffset' object has no attribute 'zone'
@bf0
Copy link
Author

bf0 commented Sep 18, 2012

ah, ran into another. Looks like:

fixed_offset_tz_DF['foo'] = pd.stats.moments.ewma(another_fixed_offset_tz_DF.b,com=9.5)

...

   /pandas-0.9.0.dev_de31cbe-py2.7-macosx-10.6-x86_64.egg/pandas/core/frame.pyc in _sanitize_column(self, key, value)
   1848         if _is_sequence(value):
   1849             if isinstance(value, Series):
-> 1850                 if value.index.equals(self.index):
   1851                     # copy the values
   1852                     value = value.values.copy()

   /pandas-0.9.0.dev_de31cbe-py2.7-macosx-10.6-x86_64.egg/pandas/tseries/index.pyc in equals(self, other)
   1221             if other.tz is None:
   1222                 return False
-> 1223             same_zone = self.tz.zone == other.tz.zone
   1224         else:
   1225             if other.tz is not None:

AttributeError: 'FixedOffsetTimezone' object has no attribute 'zone'

I can't tell if it's only possible because of a try-catch-pass on a tz.zone line I put in my local to be able to resample the dataframe in the first place (to get past the first bug mentioned here) Either way it's .zone so it can break if FixedOffsetTimezone get there. At least in terms of instances of tz.zone, this should be of the few places:

~/Workspace/lib/pandas/pandas (de31cbe) $ ack ".zone" #brew install ack

io/pytables.py
582:                node._v_attrs.tz = index.tz.zone

src/tseries.c  #Assuming these are fine (?)
30387: *                 result += self.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
30405: *                 result += self.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
30417: *                 result += self.strftime(' %%Z, tz=%s' % self.tzinfo.zone)             # <<<<<<<<<<<<<<
30461: *                 result += self.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
30475: *                 result += self.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
30498: *                 result += year2000.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
30516: *                 result += year2000.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
30528: *                 result += year2000.strftime(' %%Z, tz=%s' % self.tzinfo.zone)             # <<<<<<<<<<<<<<
30580: *                 result += year2000.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
37461: *             return tz.zone
37474: *             return tz.zone             # <<<<<<<<<<<<<<
37500: *             return tz.zone
37514: *             return tz.zone
41110: *     if tz1.zone != 'UTC':             # <<<<<<<<<<<<<<
41122: *     if tz1.zone != 'UTC':
41176: *     if tz1.zone != 'UTC':
41446: *     if tz2.zone == 'UTC':
41472: *     if tz2.zone == 'UTC':             # <<<<<<<<<<<<<<
41484: *     if tz2.zone == 'UTC':
42059: *     if tz1.zone != 'UTC':             # <<<<<<<<<<<<<<
42071: *     if tz1.zone != 'UTC':
42110: *     if tz1.zone != 'UTC':
42238: *     if tz2.zone == 'UTC':
42247: *     if tz2.zone == 'UTC':             # <<<<<<<<<<<<<<
42259: *     if tz2.zone == 'UTC':
134073: *                 result += self.strftime(' %%Z, tz=%s' % self.tzinfo.zone)
134087: *                 result += year2000.strftime(' %%Z, tz=%s' % self.tzinfo.zone)

tseries/index.py
1223:            same_zone = self.tz.zone == other.tz.zone

tseries/tests/test_timezones.py
358:        self.assert_(result.index.tz.zone == 'US/Eastern')
364:        self.assert_(result.index.tz.zone == 'US/Eastern')
390:        self.assert_(result.tz.zone == 'US/Eastern')
450:        self.assert_(index.tz.zone == 'US/Eastern')
505:        self.assert_(result.index.tz.zone == 'UTC')
510:        self.assert_(result.index.tz.zone == 'UTC')
515:        self.assert_(result.columns.tz.zone == 'UTC')
529:        self.assert_(result.index.tz.zone == 'Europe/Berlin')
534:        self.assert_(result.index.tz.zone == 'Europe/Berlin')
539:        self.assert_(result.columns.tz.zone == 'Europe/Berlin')
560:            self.assert_(result.tz.zone == 'UTC')

tseries/tools.py
30:                assert(tz.zone == b.tzinfo.zone)  #my only local ∆: try/catch/pass, in repo this is line 29

@bf0 bf0 closed this as completed Sep 18, 2012
@bf0 bf0 reopened this Sep 18, 2012
@bf0
Copy link
Author

bf0 commented Sep 18, 2012

Hey that's not the off button... and I'm going to sleep. Goodnight timezone code, sleep tight.

@ghost ghost assigned changhiskhan Sep 18, 2012
wesm added a commit that referenced this issue Sep 19, 2012
* chang/fixedoffset:
  BUG: more fixedoffset occurrences #1928
  BUG: no zone in tzinfo #1838
@wesm wesm closed this as completed Sep 19, 2012
yarikoptic added a commit to neurodebian/pandas that referenced this issue Sep 27, 2012
Version 0.9.0 Release Candidate 1

* tag 'v0.9.0rc1': (58 commits)
  RLS: Version 0.9.0 Release Candidate 1
  BLD: add lib depends pandas-dev#1945
  BUG: missing case for assigning DataFrame via ix
  BUG: python 3.1 timedelta compat issue
  BUG: python 3 tzoffset is not hashable
  TST: adds dateutil to travis-ci install commands
  BUG: let selecting multiple columns in DataFrame.__getitem__ work when there are duplicates. close pandas-dev#1943
  BUG: DatetimeConverter does not handle datetime64 arrays properly
  BUG: reindex with axis=1 when setting Series to scalar location, close pandas-dev#1942
  BUG: fix formatting of Timestamps in to_html/IPython notebook. refactor to_html code. close pandas-dev#1940
  ENH: allow single str input to na_values pandas-dev#1944
  TST: when xlrd is not installed skip tests needing it, close pandas-dev#1941
  BUG: DatetimeIndex localizes twice if input is localized DatetimeIndex pandas-dev#1838
  BUG: align input on setting via ix pandas-dev#1630
  cython methods for group bins pandas-dev#1809
  BUG: allow non-numeric columns in groupby first/last pandas-dev#1809
  TST: skip unicode filename test if system requires encoding to ascii
  BUG: more fixedoffset occurrences pandas-dev#1928
  BUG: no zone in tzinfo pandas-dev#1838
  BUG: handle lists too in DataFrame.xs when partially selecting data from DataFrame. close pandas-dev#1796
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

No branches or pull requests

3 participants