Skip to content

Commit 6d2c57f

Browse files
committed
Merge pull request #3597 from jreback/table_bug
BUG: Fixed bug where a time-series was being selected in preference to an actual column name
2 parents 8897021 + 5adf2c8 commit 6d2c57f

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

RELEASE.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ pandas 0.11.1
108108
- Fixed bug in reset_index with ``NaN`` in a multi-index (GH3586_)
109109
- ``fillna`` methods now raise a ``TypeError`` when the ``value`` parameter
110110
is a ``list`` or ``tuple``.
111+
- Fixed bug where a time-series was being selected in preference to an actual column name
112+
in a frame (GH3594_)
111113

112114
.. _GH3164: https://github.com/pydata/pandas/issues/3164
113115
.. _GH2786: https://github.com/pydata/pandas/issues/2786
@@ -150,6 +152,7 @@ pandas 0.11.1
150152
.. _GH3579: https://github.com/pydata/pandas/issues/3579
151153
.. _GH3593: https://github.com/pydata/pandas/issues/3593
152154
.. _GH3556: https://github.com/pydata/pandas/issues/3556
155+
.. _GH3594: https://github.com/pydata/pandas/issues/3594
153156
.. _GH3435: https://github.com/pydata/pandas/issues/3435
154157

155158

pandas/core/indexing.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ def _convert_to_index_sliceable(obj, key):
883883

884884
elif isinstance(key, basestring):
885885

886+
# we are an actual column
887+
if key in obj._data.items:
888+
return None
889+
886890
# we need a timelike key here
887891
if idx.is_all_dates:
888892
try:

pandas/io/tests/test_parsers.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,33 @@ def test_fwf(self):
17301730
self.assertRaises(ValueError, read_fwf, StringIO(data3),
17311731
colspecs=colspecs, widths=[6, 10, 10, 7])
17321732

1733+
def test_fwf_regression(self):
1734+
# GH 3594
1735+
#### turns out 'T060' is parsable as a datetime slice!
1736+
1737+
tzlist = [1,10,20,30,60,80,100]
1738+
ntz = len(tzlist)
1739+
tcolspecs = [16]+[8]*ntz
1740+
tcolnames = ['SST'] + ["T%03d" % z for z in tzlist[1:]]
1741+
data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192
1742+
2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869
1743+
2009164204000 9.5873 9.1326 8.4694 7.5889 6.0422 5.8526 5.4657
1744+
2009164205000 9.5810 9.0896 8.4009 7.4652 6.0322 5.8189 5.4379
1745+
2009164210000 9.6034 9.0897 8.3822 7.4905 6.0908 5.7904 5.4039
1746+
"""
1747+
1748+
df = read_fwf(StringIO(data),
1749+
index_col=0,
1750+
header=None,
1751+
names=tcolnames,
1752+
widths=tcolspecs,
1753+
parse_dates=True,
1754+
date_parser=lambda s: datetime.strptime(s,'%Y%j%H%M%S'))
1755+
1756+
for c in df.columns:
1757+
res = df.loc[:,c]
1758+
self.assert_(len(res))
1759+
17331760
def test_verbose_import(self):
17341761
text = """a,b,c,d
17351762
one,1,2,3

pandas/sparse/frame.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def shape(self):
4343
def axes(self):
4444
return [self.sp_frame.columns, self.sp_frame.index]
4545

46+
@property
47+
def items(self):
48+
return self.sp_frame.columns
49+
4650
@property
4751
def blocks(self):
4852
""" return our series in the column order """

0 commit comments

Comments
 (0)