Skip to content

Commit 8f94f9b

Browse files
committed
Merge pull request #10401 from kawochen/BUG-FIX-10392
BUG: GH10392 bug where Table.select_column does not preserve column name
2 parents 7d6fb51 + 81eba22 commit 8f94f9b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/source/whatsnew/v0.17.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ Bug Fixes
7474
- Bug in ``pd.Series`` when setting a value on an empty ``Series`` whose index has a frequency. (:issue:`10193`)
7575
- Bug in ``DataFrame.reset_index`` when index contains `NaT`. (:issue:`10388`)
7676
- Bug in ``ExcelReader`` when worksheet is empty (:issue:`6403`)
77+
- Bug in ``Table.select_column`` where name is not preserved (:issue:`10392`)

pandas/io/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3608,7 +3608,7 @@ def read_column(self, column, where=None, start=None, stop=None, **kwargs):
36083608
nan_rep=self.nan_rep,
36093609
encoding=self.encoding
36103610
).take_data(),
3611-
a.tz, True))
3611+
a.tz, True), name=column)
36123612

36133613
raise KeyError("column [%s] not found in the table" % column)
36143614

pandas/io/tests/test_pytables.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,7 @@ def f():
37663766
# valid
37673767
result = store.select_column('df', 'index')
37683768
tm.assert_almost_equal(result.values, Series(df.index).values)
3769-
self.assertIsInstance(result,Series)
3769+
self.assertIsInstance(result, Series)
37703770

37713771
# not a data indexable column
37723772
self.assertRaises(
@@ -3806,6 +3806,14 @@ def f():
38063806
result = store.select_column('df3', 'string', start=-2, stop=2)
38073807
tm.assert_almost_equal(result.values, df3['string'].values[-2:2])
38083808

3809+
# GH 10392 - make sure column name is preserved
3810+
df4 = DataFrame({'A': np.random.randn(10), 'B': 'foo'})
3811+
store.append('df4', df4, data_columns=True)
3812+
expected = df4['B']
3813+
result = store.select_column('df4', 'B')
3814+
tm.assert_series_equal(result, expected)
3815+
3816+
38093817
def test_coordinates(self):
38103818
df = tm.makeTimeDataFrame()
38113819

0 commit comments

Comments
 (0)