Skip to content

BUG: Fixed bug where a time-series was being selected in preference to an actual column name #3597

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
May 14, 2013
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
3 changes: 3 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 27 additions & 0 deletions pandas/io/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pandas/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down