Skip to content

Commit 69ed301

Browse files
committed
Fix tests so no warnings are generated in Column() calls
This is only complete for table and io.ascii. All of these tests run without generating warnings. This was done to be sure that all code in astropy.table and astropy.io.ascii is fully compliant with the new Column args checking, i.e. it will never happen that a call to astropy.Table can generate a warning to the user.
1 parent 716dde9 commit 69ed301

File tree

7 files changed

+91
-91
lines changed

7 files changed

+91
-91
lines changed

astropy/io/ascii/tests/test_connect.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def test_read_generic(filename):
1818

1919
def test_write_generic(tmpdir):
2020
t = Table()
21-
t.add_column(Column('a', [1,2,3]))
22-
t.add_column(Column('b', ['a', 'b', 'c']))
21+
t.add_column(Column(name='a', data=[1,2,3]))
22+
t.add_column(Column(name='b', data=['a', 'b', 'c']))
2323
t.write(str(tmpdir.join("test")), format='ascii')
2424

2525

@@ -47,16 +47,16 @@ def test_read_latex_noformat():
4747

4848
def test_write_latex(tmpdir):
4949
t = Table()
50-
t.add_column(Column('a', [1,2,3]))
51-
t.add_column(Column('b', ['a', 'b', 'c']))
50+
t.add_column(Column(name='a', data=[1,2,3]))
51+
t.add_column(Column(name='b', data=['a', 'b', 'c']))
5252
path = str(tmpdir.join("data.tex"))
5353
t.write(path, format='latex')
5454

5555

5656
def test_write_latex_noformat(tmpdir):
5757
t = Table()
58-
t.add_column(Column('a', [1,2,3]))
59-
t.add_column(Column('b', ['a', 'b', 'c']))
58+
t.add_column(Column(name='a', data=[1,2,3]))
59+
t.add_column(Column(name='b', data=['a', 'b', 'c']))
6060
path = str(tmpdir.join("data.tex"))
6161
t.write(path)
6262

@@ -71,15 +71,15 @@ def test_read_rdb_noformat():
7171

7272
def test_write_rdb(tmpdir):
7373
t = Table()
74-
t.add_column(Column('a', [1,2,3]))
75-
t.add_column(Column('b', ['a', 'b', 'c']))
74+
t.add_column(Column(name='a', data=[1,2,3]))
75+
t.add_column(Column(name='b', data=['a', 'b', 'c']))
7676
path = str(tmpdir.join("data.rdb"))
7777
t.write(path, format='rdb')
7878

7979

8080
def test_write_rdb_noformat(tmpdir):
8181
t = Table()
82-
t.add_column(Column('a', [1,2,3]))
83-
t.add_column(Column('b', ['a', 'b', 'c']))
82+
t.add_column(Column(name='a', data=[1,2,3]))
83+
t.add_column(Column(name='b', data=['a', 'b', 'c']))
8484
path = str(tmpdir.join("data.rdb"))
8585
t.write(path)

astropy/table/tests/test_column.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def Column(request):
1717
class TestColumn():
1818

1919
def test_1(self, Column):
20-
Column('a')
20+
Column(name='a')
2121

2222
def test_subclass(self, Column):
23-
c = Column('a')
23+
c = Column(name='a')
2424
assert isinstance(c, np.ndarray)
2525
c2 = c * 2
2626
assert isinstance(c2, Column)
@@ -30,7 +30,7 @@ def test_numpy_ops(self, Column):
3030
"""Show that basic numpy operations with Column behave sensibly"""
3131

3232
arr = np.array([1, 2, 3])
33-
c = Column('a', arr)
33+
c = Column(name='a', data=arr)
3434
eq = c == arr
3535
assert np.all(eq)
3636
assert len(eq) == 3
@@ -64,7 +64,7 @@ def test_format(self, Column):
6464
table.pprint.MAX_LINES.set(MAX_LINES_val)
6565

6666
def test_convert_numpy_array(self, Column):
67-
d = Column('a', [1, 2, 3], dtype='i8')
67+
d = Column(name='a', data=[1, 2, 3], dtype='i8')
6868

6969
np_data = np.array(d)
7070
assert np.all(np_data == d)
@@ -74,7 +74,7 @@ def test_convert_numpy_array(self, Column):
7474
assert np.all(np_data == d)
7575

7676
def test_convert_units(self, Column):
77-
d = Column('a', [1, 2, 3], dtype="f8", units="m")
77+
d = Column(name='a', data=[1, 2, 3], dtype="f8", units="m")
7878
d.convert_units_to("km")
7979
assert np.all(d.data == [0.001, 0.002, 0.003])
8080

@@ -83,7 +83,7 @@ def test_array_wrap(self):
8383
output that has a different shape into an ndarray view. Without this a
8484
method call like c.mean() returns a Column array object with length=1."""
8585
# Mean and sum for a 1-d float column
86-
c = table.Column('a', [1., 2., 3.])
86+
c = table.Column(name='a', data=[1., 2., 3.])
8787
assert np.allclose(c.mean(), 2.0)
8888
assert isinstance(c.mean(), (np.floating, float))
8989
assert np.allclose(c.sum(), 6.)
@@ -93,13 +93,13 @@ def test_array_wrap(self):
9393
assert isinstance(np.cos(c), table.Column)
9494

9595
# Sum for a 1-d int column
96-
c = table.Column('a', [1, 2, 3])
96+
c = table.Column(name='a', data=[1, 2, 3])
9797
assert np.allclose(c.sum(), 6)
9898
assert isinstance(c.sum(), (np.integer, int))
9999

100100
# Sum for a 2-d int column
101-
c = table.Column('a', [[1, 2, 3],
102-
[4, 5, 6]])
101+
c = table.Column(name='a', data=[[1, 2, 3],
102+
[4, 5, 6]])
103103
assert c.sum() == 21
104104
assert isinstance(c.sum(), (np.integer, int))
105105
assert np.all(c.sum(axis=0) == [5, 7, 9])
@@ -108,7 +108,7 @@ def test_array_wrap(self):
108108

109109
if not numpy_lt_1p5:
110110
# Sum and mean for a 1-d masked column
111-
c = table.MaskedColumn('a', [1., 2., 3.], mask=[0, 0, 1])
111+
c = table.MaskedColumn(name='a', data=[1., 2., 3.], mask=[0, 0, 1])
112112
assert np.allclose(c.mean(), 1.5)
113113
assert isinstance(c.mean(), (np.floating, float))
114114
assert np.allclose(c.sum(), 3.)

astropy/table/tests/test_init_table.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class TestInitFromListOfLists(BaseInitFromListLike):
123123

124124
def setup_method(self, method):
125125
self.data = [(np.int32(1), np.int32(3)),
126-
Column('col1', [2, 4], dtype=np.int32),
126+
Column(name='col1', data=[2, 4], dtype=np.int32),
127127
np.array([3, 5], dtype=np.int32)]
128128

129129
def test_default_names(self):
@@ -150,7 +150,7 @@ def test_bad_data(self):
150150
class TestInitFromColsList(BaseInitFromListLike):
151151

152152
def setup_method(self, method):
153-
self.data = [Column('x', [1, 3], dtype=np.int32),
153+
self.data = [Column(name='x', data=[1, 3], dtype=np.int32),
154154
np.array([2, 4], dtype=np.int32),
155155
np.array([3, 5], dtype='i8')]
156156

@@ -212,7 +212,7 @@ def test_partial_names_ref(self):
212212
class TestInitFromDict(BaseInitFromDictLike):
213213

214214
def setup_method(self, method):
215-
self.data = dict([('a', Column('x', [1, 3])),
215+
self.data = dict([('a', Column(name='x', data=[1, 3])),
216216
('b', [2, 4]),
217217
('c', np.array([3, 5], dtype='i8'))])
218218

@@ -221,7 +221,7 @@ def setup_method(self, method):
221221
class TestInitFromOrderedDict(BaseInitFromDictLike):
222222

223223
def setup_method(self, method):
224-
self.data = OrderedDict([('a', Column('x', [1, 3])),
224+
self.data = OrderedDict([('a', Column(name='x', data=[1, 3])),
225225
('b', [2, 4]),
226226
('c', np.array([3, 5], dtype='i8'))])
227227

astropy/table/tests/test_item_access.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ def set_global_Table_DATA(request):
3131

3232
Table = MaskedTable if request.param else table.Table
3333
Column = table.MaskedColumn if request.param else table.Column
34-
COLS = [Column('a', [1, 2, 3], description='da',
34+
COLS = [Column(name='a', data=[1, 2, 3], description='da',
3535
format='fa', meta={'ma': 1}, units='ua'),
36-
Column('b', [4, 5, 6], description='db',
36+
Column(name='b', data=[4, 5, 6], description='db',
3737
format='fb', meta={'mb': 1}, units='ub'),
38-
Column('c', [7, 8, 9], description='dc',
38+
Column(name='c', data=[7, 8, 9], description='dc',
3939
format='fc', meta={'mc': 1}, units='ub')]
4040
DATA = Table(COLS)
4141

astropy/table/tests/test_masked.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
class SetupData(object):
1515
def setup_method(self, method):
16-
self.a = MaskedColumn('a', [1, 2, 3], fill_value=1)
17-
self.b = MaskedColumn('b', [4, 5, 6], mask=True)
18-
self.c = MaskedColumn('c', [7, 8, 9], mask=False)
16+
self.a = MaskedColumn(name='a', data=[1, 2, 3], fill_value=1)
17+
self.b = MaskedColumn(name='b', data=[4, 5, 6], mask=True)
18+
self.c = MaskedColumn(name='c', data=[7, 8, 9], mask=False)
1919
self.d_mask = np.array([False, True, False])
20-
self.d = MaskedColumn('d', [7, 8, 7], mask=self.d_mask)
20+
self.d = MaskedColumn(name='d', data=[7, 8, 7], mask=self.d_mask)
2121
self.t = Table([self.a, self.b], masked=True)
22-
self.ca = Column('ca', [1, 2, 3])
22+
self.ca = Column(name='ca', data=[1, 2, 3])
2323

2424

2525
@pytest.mark.xfail('numpy_lt_1p5')
@@ -34,9 +34,9 @@ class TestFilled(object):
3434
def setup_method(self, method):
3535
mask = [True, False, False]
3636
self.meta = {'a': 1, 'b': [2, 3]}
37-
a = self.a = MaskedColumn('a', [1, 2, 3], fill_value=10, mask=mask, meta={'a': 1})
38-
b = self.b = MaskedColumn('b', [4.0, 5.0, 6.0], fill_value=10.0, mask=mask)
39-
c = self.c = MaskedColumn('c', ['7', '8', '9'], fill_value='1', mask=mask)
37+
a = self.a = MaskedColumn(name='a', data=[1, 2, 3], fill_value=10, mask=mask, meta={'a': 1})
38+
b = self.b = MaskedColumn(name='b', data=[4.0, 5.0, 6.0], fill_value=10.0, mask=mask)
39+
c = self.c = MaskedColumn(name='c', data=['7', '8', '9'], fill_value='1', mask=mask)
4040

4141
def test_filled_column(self):
4242
f = self.a.filled()
@@ -103,7 +103,7 @@ class TestFillValue(SetupData):
103103
def test_init_set_fill_value(self):
104104
"""Check that setting fill_value in the MaskedColumn init works"""
105105
assert self.a.fill_value == 1
106-
c = MaskedColumn('c', ['xxxx', 'yyyy'], fill_value='none')
106+
c = MaskedColumn(name='c', data=['xxxx', 'yyyy'], fill_value='none')
107107
assert c.fill_value == 'none'
108108

109109
def test_set_get_fill_value_for_bare_column(self):
@@ -113,7 +113,7 @@ def test_set_get_fill_value_for_bare_column(self):
113113
assert np.all(self.d.filled() == [7, -999, 7])
114114

115115
def test_set_get_fill_value_for_str_column(self):
116-
c = MaskedColumn('c', ['xxxx', 'yyyy'], mask=[True, False])
116+
c = MaskedColumn(name='c', data=['xxxx', 'yyyy'], mask=[True, False])
117117
# assert np.all(c.filled() == ['N/A', 'yyyy'])
118118
c.fill_value = 'ABCDEF'
119119
assert c.fill_value == 'ABCD' # string truncated to dtype length
@@ -156,19 +156,19 @@ def test_set_mask_and_not_ref(self):
156156
def test_set_mask_from_list(self):
157157
"""Set mask from a list"""
158158
mask_list = [False, True, False]
159-
a = MaskedColumn('a', [1, 2, 3], mask=mask_list)
159+
a = MaskedColumn(name='a', data=[1, 2, 3], mask=mask_list)
160160
assert np.all(a.mask == mask_list)
161161

162162
def test_override_existing_mask(self):
163163
"""Override existing mask values"""
164164
mask_list = [False, True, False]
165-
b = MaskedColumn('b', self.b, mask=mask_list)
165+
b = MaskedColumn(name='b', data=self.b, mask=mask_list)
166166
assert np.all(b.mask == mask_list)
167167

168168
def test_incomplete_mask_spec(self):
169169
"""Incomplete mask specification (mask values cycle through available)"""
170170
mask_list = [False, True]
171-
b = MaskedColumn('b', length=4, mask=mask_list)
171+
b = MaskedColumn(name='b', length=4, mask=mask_list)
172172
assert np.all(b.mask == mask_list + mask_list)
173173

174174

@@ -204,9 +204,9 @@ class TestAddColumn(object):
204204
def test_add_masked_column_to_masked_table(self):
205205
t = Table(masked=True)
206206
assert t.masked
207-
t.add_column(MaskedColumn('a', [1,2,3], mask=[0,1,0]))
207+
t.add_column(MaskedColumn(name='a', data=[1,2,3], mask=[0,1,0]))
208208
assert t.masked
209-
t.add_column(MaskedColumn('b', [4,5,6], mask=[1,0,1]))
209+
t.add_column(MaskedColumn(name='b', data=[4,5,6], mask=[1,0,1]))
210210
assert t.masked
211211
assert np.all(t['a'] == np.array([1,2,3]))
212212
assert np.all(t['a'].mask == np.array([0,1,0], bool))
@@ -216,9 +216,9 @@ def test_add_masked_column_to_masked_table(self):
216216
def test_add_masked_column_to_non_masked_table(self):
217217
t = Table(masked=False)
218218
assert not t.masked
219-
t.add_column(Column('a', [1,2,3]))
219+
t.add_column(Column(name='a', data=[1,2,3]))
220220
assert not t.masked
221-
t.add_column(MaskedColumn('b', [4,5,6], mask=[1,0,1]))
221+
t.add_column(MaskedColumn(name='b', data=[4,5,6], mask=[1,0,1]))
222222
assert t.masked
223223
assert np.all(t['a'] == np.array([1,2,3]))
224224
assert np.all(t['a'].mask == np.array([0,0,0], bool))
@@ -228,9 +228,9 @@ def test_add_masked_column_to_non_masked_table(self):
228228
def test_add_non_masked_column_to_masked_table(self):
229229
t = Table(masked=True)
230230
assert t.masked
231-
t.add_column(Column('a', [1,2,3]))
231+
t.add_column(Column(name='a', data=[1,2,3]))
232232
assert t.masked
233-
t.add_column(MaskedColumn('b', [4,5,6], mask=[1,0,1]))
233+
t.add_column(MaskedColumn(name='b', data=[4,5,6], mask=[1,0,1]))
234234
assert t.masked
235235
assert np.all(t['a'] == np.array([1,2,3]))
236236
assert np.all(t['a'].mask == np.array([0,0,0], bool))
@@ -243,8 +243,8 @@ class TestAddRow(object):
243243

244244
def test_add_masked_row_to_masked_table_iterable(self):
245245
t = Table(masked=True)
246-
t.add_column(MaskedColumn('a', [1], mask=[0]))
247-
t.add_column(MaskedColumn('b', [4], mask=[1]))
246+
t.add_column(MaskedColumn(name='a', data=[1], mask=[0]))
247+
t.add_column(MaskedColumn(name='b', data=[4], mask=[1]))
248248
t.add_row([2,5], mask=[1,0])
249249
t.add_row([3,6], mask=[0,1])
250250
assert t.masked
@@ -255,8 +255,8 @@ def test_add_masked_row_to_masked_table_iterable(self):
255255

256256
def test_add_masked_row_to_masked_table_mapping1(self):
257257
t = Table(masked=True)
258-
t.add_column(MaskedColumn('a', [1], mask=[0]))
259-
t.add_column(MaskedColumn('b', [4], mask=[1]))
258+
t.add_column(MaskedColumn(name='a', data=[1], mask=[0]))
259+
t.add_column(MaskedColumn(name='b', data=[4], mask=[1]))
260260
t.add_row({'b':5, 'a':2}, mask={'a':1, 'b':0})
261261
t.add_row({'a':3, 'b':6}, mask={'b':1, 'a':0})
262262
assert t.masked
@@ -269,8 +269,8 @@ def test_add_masked_row_to_masked_table_mapping2(self):
269269
# When adding values to a masked table, if the mask is specified as a
270270
# dict, then values not specified will have mask values set to True
271271
t = Table(masked=True)
272-
t.add_column(MaskedColumn('a', [1], mask=[0]))
273-
t.add_column(MaskedColumn('b', [4], mask=[1]))
272+
t.add_column(MaskedColumn(name='a', data=[1], mask=[0]))
273+
t.add_column(MaskedColumn(name='b', data=[4], mask=[1]))
274274
t.add_row({'b':5}, mask={'b':0})
275275
t.add_row({'a':3}, mask={'a':0})
276276
assert t.masked
@@ -284,8 +284,8 @@ def test_add_masked_row_to_masked_table_mapping3(self):
284284
# add_row, then the mask should be set to False if values are present
285285
# and True if not.
286286
t = Table(masked=True)
287-
t.add_column(MaskedColumn('a', [1], mask=[0]))
288-
t.add_column(MaskedColumn('b', [4], mask=[1]))
287+
t.add_column(MaskedColumn(name='a', data=[1], mask=[0]))
288+
t.add_column(MaskedColumn(name='b', data=[4], mask=[1]))
289289
t.add_row({'b':5})
290290
t.add_row({'a':3})
291291
assert t.masked
@@ -298,16 +298,16 @@ def test_add_masked_row_to_masked_table_mapping4(self):
298298
# When adding values to a masked table, if the mask is specified as a
299299
# dict, then keys in values should match keys in mask
300300
t = Table(masked=True)
301-
t.add_column(MaskedColumn('a', [1], mask=[0]))
302-
t.add_column(MaskedColumn('b', [4], mask=[1]))
301+
t.add_column(MaskedColumn(name='a', data=[1], mask=[0]))
302+
t.add_column(MaskedColumn(name='b', data=[4], mask=[1]))
303303
with pytest.raises(ValueError) as exc:
304304
t.add_row({'b':5}, mask={'a':True})
305305
assert exc.value.args[0] == 'keys in mask should match keys in vals'
306306

307307
def test_add_masked_row_to_masked_table_mismatch(self):
308308
t = Table(masked=True)
309-
t.add_column(MaskedColumn('a', [1], mask=[0]))
310-
t.add_column(MaskedColumn('b', [4], mask=[1]))
309+
t.add_column(MaskedColumn(name='a', data=[1], mask=[0]))
310+
t.add_column(MaskedColumn(name='b', data=[4], mask=[1]))
311311
with pytest.raises(TypeError) as exc:
312312
t.add_row([2,5], mask={'a':1, 'b':0})
313313
assert exc.value.args[0] == "Mismatch between type of vals and mask"
@@ -317,8 +317,8 @@ def test_add_masked_row_to_masked_table_mismatch(self):
317317

318318
def test_add_masked_row_to_non_masked_table_iterable(self):
319319
t = Table(masked=False)
320-
t.add_column(Column('a', [1]))
321-
t.add_column(Column('b', [4]))
320+
t.add_column(Column(name='a', data=[1]))
321+
t.add_column(Column(name='b', data=[4]))
322322
assert not t.masked
323323
t.add_row([2,5])
324324
assert not t.masked

astropy/table/tests/test_row.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def t(self):
3939
if Column is None:
4040
return None
4141
if not hasattr(self, '_t'):
42-
a = Column('a', [1, 2, 3], dtype='i8')
43-
b = Column('b', [4, 5, 6], dtype='i8')
42+
a = Column(name='a', data=[1, 2, 3], dtype='i8')
43+
b = Column(name='b', data=[4, 5, 6], dtype='i8')
4444
self._t = Table([a, b])
4545
return self._t
4646

0 commit comments

Comments
 (0)