From 5adf2c849825b51205743b7ff6f4b6a0b6c5cdfe Mon Sep 17 00:00:00 2001 From: jreback Date: Mon, 13 May 2013 20:32:45 -0400 Subject: [PATCH] BUG: Fixed bug where a time-series was being selected in preference to an actual column name in a frame (GH3594_) --- RELEASE.rst | 3 +++ pandas/core/indexing.py | 4 ++++ pandas/io/tests/test_parsers.py | 27 +++++++++++++++++++++++++++ pandas/sparse/frame.py | 4 ++++ 4 files changed, 38 insertions(+) diff --git a/RELEASE.rst b/RELEASE.rst index 70060ee1b3497..31627cec01d1e 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -108,6 +108,8 @@ pandas 0.11.1 - Fixed bug in reset_index with ``NaN`` in a multi-index (GH3586_) - ``fillna`` methods now raise a ``TypeError`` when the ``value`` parameter is a ``list`` or ``tuple``. + - Fixed bug where a time-series was being selected in preference to an actual column name + in a frame (GH3594_) .. _GH3164: https://github.com/pydata/pandas/issues/3164 .. _GH2786: https://github.com/pydata/pandas/issues/2786 @@ -150,6 +152,7 @@ pandas 0.11.1 .. _GH3579: https://github.com/pydata/pandas/issues/3579 .. _GH3593: https://github.com/pydata/pandas/issues/3593 .. _GH3556: https://github.com/pydata/pandas/issues/3556 +.. _GH3594: https://github.com/pydata/pandas/issues/3594 .. _GH3435: https://github.com/pydata/pandas/issues/3435 diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 8b6acd8c7c53e..bc8b7a3646a33 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -883,6 +883,10 @@ def _convert_to_index_sliceable(obj, key): elif isinstance(key, basestring): + # we are an actual column + if key in obj._data.items: + return None + # we need a timelike key here if idx.is_all_dates: try: diff --git a/pandas/io/tests/test_parsers.py b/pandas/io/tests/test_parsers.py index 5ff832431c917..2e4689d7aa620 100644 --- a/pandas/io/tests/test_parsers.py +++ b/pandas/io/tests/test_parsers.py @@ -1730,6 +1730,33 @@ def test_fwf(self): self.assertRaises(ValueError, read_fwf, StringIO(data3), colspecs=colspecs, widths=[6, 10, 10, 7]) + def test_fwf_regression(self): + # GH 3594 + #### turns out 'T060' is parsable as a datetime slice! + + tzlist = [1,10,20,30,60,80,100] + ntz = len(tzlist) + tcolspecs = [16]+[8]*ntz + tcolnames = ['SST'] + ["T%03d" % z for z in tzlist[1:]] + data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192 + 2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869 + 2009164204000 9.5873 9.1326 8.4694 7.5889 6.0422 5.8526 5.4657 + 2009164205000 9.5810 9.0896 8.4009 7.4652 6.0322 5.8189 5.4379 + 2009164210000 9.6034 9.0897 8.3822 7.4905 6.0908 5.7904 5.4039 +""" + + df = read_fwf(StringIO(data), + index_col=0, + header=None, + names=tcolnames, + widths=tcolspecs, + parse_dates=True, + date_parser=lambda s: datetime.strptime(s,'%Y%j%H%M%S')) + + for c in df.columns: + res = df.loc[:,c] + self.assert_(len(res)) + def test_verbose_import(self): text = """a,b,c,d one,1,2,3 diff --git a/pandas/sparse/frame.py b/pandas/sparse/frame.py index e893f83f6d640..9694cc005d178 100644 --- a/pandas/sparse/frame.py +++ b/pandas/sparse/frame.py @@ -43,6 +43,10 @@ def shape(self): def axes(self): return [self.sp_frame.columns, self.sp_frame.index] + @property + def items(self): + return self.sp_frame.columns + @property def blocks(self): """ return our series in the column order """