diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index 168fd803c5f8a..9293c6b36879b 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -74,3 +74,4 @@ Bug Fixes - Bug in ``pd.Series`` when setting a value on an empty ``Series`` whose index has a frequency. (:issue:`10193`) - Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`) - Bug in ``ExcelReader`` when worksheet is empty (:issue:`6403`) +- Bug in ``Table.select_column`` where name is not preserved (:issue:`10392`) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 31f649c498c14..92208c37f787b 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3608,7 +3608,7 @@ def read_column(self, column, where=None, start=None, stop=None, **kwargs): nan_rep=self.nan_rep, encoding=self.encoding ).take_data(), - a.tz, True)) + a.tz, True), name=column) raise KeyError("column [%s] not found in the table" % column) diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 6aaeb6652f2b6..e9c39127d1032 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -3766,7 +3766,7 @@ def f(): # valid result = store.select_column('df', 'index') tm.assert_almost_equal(result.values, Series(df.index).values) - self.assertIsInstance(result,Series) + self.assertIsInstance(result, Series) # not a data indexable column self.assertRaises( @@ -3806,6 +3806,14 @@ def f(): result = store.select_column('df3', 'string', start=-2, stop=2) tm.assert_almost_equal(result.values, df3['string'].values[-2:2]) + # GH 10392 - make sure column name is preserved + df4 = DataFrame({'A': np.random.randn(10), 'B': 'foo'}) + store.append('df4', df4, data_columns=True) + expected = df4['B'] + result = store.select_column('df4', 'B') + tm.assert_series_equal(result, expected) + + def test_coordinates(self): df = tm.makeTimeDataFrame()