本文整理汇总了Python中astropy.table.join方法的典型用法代码示例。如果您正苦于以下问题:Python table.join方法的具体用法?Python table.join怎么用?Python table.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.table
的用法示例。
在下文中一共展示了table.join方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_both_unmasked_single_key_inner
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_both_unmasked_single_key_inner(self, operation_table_type):
self._setup(operation_table_type)
t1 = self.t1
t2 = self.t2
# Inner join on 'a' column
t12 = table.join(t1, t2, keys='a')
assert type(t12) is operation_table_type
assert type(t12['a']) is type(t1['a'])
assert type(t12['b_1']) is type(t1['b'])
assert type(t12['c']) is type(t1['c'])
assert type(t12['b_2']) is type(t2['b'])
assert type(t12['d']) is type(t2['d'])
assert t12.masked is False
assert sort_eq(t12.pformat(), [' a b_1 c b_2 d ',
'--- --- --- --- ---',
' 1 foo L2 foo R1',
' 1 foo L2 foo R2',
' 1 bar L3 foo R1',
' 1 bar L3 foo R2',
' 2 bar L4 bar R3'])
示例2: test_join_multidimensional
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_join_multidimensional(self, operation_table_type):
self._setup(operation_table_type)
# Regression test for #2984, which was an issue where join did not work
# on multi-dimensional columns.
t1 = operation_table_type()
t1['a'] = [1, 2, 3]
t1['b'] = np.ones((3, 4))
t2 = operation_table_type()
t2['a'] = [1, 2, 3]
t2['c'] = [4, 5, 6]
t3 = table.join(t1, t2)
np.testing.assert_allclose(t3['a'], t1['a'])
np.testing.assert_allclose(t3['b'], t1['b'])
np.testing.assert_allclose(t3['c'], t2['c'])
示例3: test_cartesian_join
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_cartesian_join(self, operation_table_type):
t1 = Table(rows=[(1, 'a'),
(2, 'b')], names=['a', 'b'])
t2 = Table(rows=[(3, 'c'),
(4, 'd')], names=['a', 'c'])
t12 = table.join(t1, t2, join_type='cartesian')
assert t1.colnames == ['a', 'b']
assert t2.colnames == ['a', 'c']
assert len(t12) == len(t1) * len(t2)
assert str(t12).splitlines() == [
'a_1 b a_2 c ',
'--- --- --- ---',
' 1 a 3 c',
' 1 a 4 d',
' 2 b 3 c',
' 2 b 4 d']
with pytest.raises(ValueError, match='cannot supply keys for a cartesian join'):
t12 = table.join(t1, t2, join_type='cartesian', keys='a')
示例4: test_masking_required_exception
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_masking_required_exception():
"""
Test that outer join, hstack and vstack fail for a mixin column which
does not support masking.
"""
col = [1, 2, 3, 4] * u.m
t1 = table.QTable([[1, 2, 3, 4], col], names=['a', 'b'])
t2 = table.QTable([[1, 2], col[:2]], names=['a', 'c'])
with pytest.raises(NotImplementedError) as err:
table.vstack([t1, t2], join_type='outer')
assert 'vstack requires masking' in str(err.value)
with pytest.raises(NotImplementedError) as err:
table.hstack([t1, t2], join_type='outer')
assert 'hstack requires masking' in str(err.value)
with pytest.raises(NotImplementedError) as err:
table.join(t1, t2, join_type='outer')
assert 'join requires masking' in str(err.value)
示例5: __repr__
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def __repr__(self, html=False):
out = 'SearchResult containing {} data products.'.format(len(self.table))
if len(self.table) == 0:
return out
columns = ['#', 'observation', 'target_name', 'productFilename', 'distance']
return out + '\n\n' + '\n'.join(self.table[columns].pformat(max_width=300, html=html))
示例6: _default_download_dir
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def _default_download_dir(self):
"""Returns the default path to the directory where files will be downloaded.
By default, this method will return "~/.lightkurve-cache" and create
this directory if it does not exist. If the directory cannot be
access or created, then it returns the local directory (".").
Returns
-------
download_dir : str
Path to location of `mastDownload` folder where data downloaded from MAST are stored
"""
download_dir = os.path.join(os.path.expanduser('~'), '.lightkurve-cache')
if os.path.isdir(download_dir):
return download_dir
else:
# if it doesn't exist, make a new cache directory
try:
os.mkdir(download_dir)
# downloads locally if OS error occurs
except OSError:
log.warning('Warning: unable to create {}. '
'Downloading MAST files to the current '
'working directory instead.'.format(download_dir))
download_dir = '.'
return download_dir
示例7: reduce_data
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def reduce_data(date, tree='gama', subjectset='gama09',
survey_id_field='provided_image_id',
subjectcat='galaxy_zoo_subjects_lee.csv.gz'):
"""Do everything to produce reduced table of ids and vote fractions"""
questions, answers = parse_tree(tree)
template = '{}_galaxy_zoo_{}_classifications.csv'
indata = Table.read(template.format(date, subjectset), fast_reader=False)
outdata = collate_classifications(indata, tree, questions, answers)
outdata = recalculate_odd_total(outdata)
outdata = calculate_fractions(outdata, questions, answers)
subjects = read_subjects(subjectcat, tree, survey_id_field)
outdata = join(outdata, subjects, 'subject_id')
return outdata
示例8: test_join
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_join(self):
ts_other = self.series.copy()
ts_other.add_row(self._row)
ts_other['d'] = [11, 22, 33, 44]
ts_other.remove_columns(['a', 'b'])
ts = join(self.series, ts_other)
assert len(ts) == len(self.series)
ts = join(self.series, ts_other, join_type='outer')
assert len(ts) == len(ts_other)
示例9: test_votable_quantity_write
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_votable_quantity_write(tmpdir):
"""
Test that table with Quantity mixin column can be round-tripped by
io.votable. Note that FITS and HDF5 mixin support are tested (much more
thoroughly) in their respective subpackage tests
(io/fits/tests/test_connect.py and io/misc/tests/test_hdf5.py).
"""
t = QTable()
t['a'] = u.Quantity([1, 2, 4], unit='Angstrom')
filename = str(tmpdir.join('table-tmp'))
t.write(filename, format='votable', overwrite=True)
qt = QTable.read(filename, format='votable')
assert isinstance(qt['a'], u.Quantity)
assert qt['a'].unit == 'Angstrom'
示例10: test_table_meta_merge
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_table_meta_merge(self, operation_table_type):
self._setup(operation_table_type)
out = table.join(self.t1, self.t2, join_type='inner')
assert out.meta == self.meta_merge
示例11: test_table_meta_merge_conflict
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_table_meta_merge_conflict(self, operation_table_type):
self._setup(operation_table_type)
with catch_warnings() as w:
out = table.join(self.t1, self.t3, join_type='inner')
assert len(w) == 3
assert out.meta == self.t3.meta
with catch_warnings() as w:
out = table.join(self.t1, self.t3, join_type='inner', metadata_conflicts='warn')
assert len(w) == 3
assert out.meta == self.t3.meta
with catch_warnings() as w:
out = table.join(self.t1, self.t3, join_type='inner', metadata_conflicts='silent')
assert len(w) == 0
assert out.meta == self.t3.meta
with pytest.raises(MergeConflictError):
out = table.join(self.t1, self.t3, join_type='inner', metadata_conflicts='error')
with pytest.raises(ValueError):
out = table.join(self.t1, self.t3, join_type='inner', metadata_conflicts='nonsense')
示例12: test_masked_unmasked
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_masked_unmasked(self, operation_table_type):
if operation_table_type is QTable:
pytest.xfail('Quantity columns do not support masking.')
self._setup(operation_table_type)
t1 = self.t1
t1m = operation_table_type(self.t1, masked=True)
t2 = self.t2
# Result table is never masked
t1m2 = table.join(t1m, t2, join_type='inner')
assert t1m2.masked is False
# Result should match non-masked result
t12 = table.join(t1, t2)
assert np.all(t12.as_array() == np.array(t1m2))
# Mask out some values in left table and make sure they propagate
t1m['b'].mask[1] = True
t1m['c'].mask[2] = True
t1m2 = table.join(t1m, t2, join_type='inner', keys='a')
assert sort_eq(t1m2.pformat(), [' a b_1 c b_2 d ',
'--- --- --- --- ---',
' 1 -- L2 foo R1',
' 1 -- L2 foo R2',
' 1 bar -- foo R1',
' 1 bar -- foo R2',
' 2 bar L4 bar R3'])
t21m = table.join(t2, t1m, join_type='inner', keys='a')
assert sort_eq(t21m.pformat(), [' a b_1 d b_2 c ',
'--- --- --- --- ---',
' 1 foo R2 -- L2',
' 1 foo R2 bar --',
' 1 foo R1 -- L2',
' 1 foo R1 bar --',
' 2 bar R3 bar L4'])
示例13: test_masked_masked
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_masked_masked(self, operation_table_type):
self._setup(operation_table_type)
"""Two masked tables"""
if operation_table_type is QTable:
pytest.xfail('Quantity columns do not support masking.')
t1 = self.t1
t1m = operation_table_type(self.t1, masked=True)
t2 = self.t2
t2m = operation_table_type(self.t2, masked=True)
# Result table is never masked but original column types are preserved
t1m2m = table.join(t1m, t2m, join_type='inner')
assert t1m2m.masked is False
for col in t1m2m.itercols():
assert type(col) is MaskedColumn
# Result should match non-masked result
t12 = table.join(t1, t2)
assert np.all(t12.as_array() == np.array(t1m2m))
# Mask out some values in both tables and make sure they propagate
t1m['b'].mask[1] = True
t1m['c'].mask[2] = True
t2m['d'].mask[2] = True
t1m2m = table.join(t1m, t2m, join_type='inner', keys='a')
assert sort_eq(t1m2m.pformat(), [' a b_1 c b_2 d ',
'--- --- --- --- ---',
' 1 -- L2 foo R1',
' 1 -- L2 foo R2',
' 1 bar -- foo R1',
' 1 bar -- foo R2',
' 2 bar L4 bar --'])
示例14: test_col_rename
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_col_rename(self, operation_table_type):
self._setup(operation_table_type)
"""
Test auto col renaming when there is a conflict. Use
non-default values of uniq_col_name and table_names.
"""
t1 = self.t1
t2 = self.t2
t12 = table.join(t1, t2, uniq_col_name='x_{table_name}_{col_name}_y',
table_names=['L', 'R'], keys='a')
assert t12.colnames == ['a', 'x_L_b_y', 'c', 'x_R_b_y', 'd']
示例15: test_rename_conflict
# 需要导入模块: from astropy import table [as 别名]
# 或者: from astropy.table import join [as 别名]
def test_rename_conflict(self, operation_table_type):
self._setup(operation_table_type)
"""
Test that auto-column rename fails because of a conflict
with an existing column
"""
t1 = self.t1
t2 = self.t2
t1['b_1'] = 1 # Add a new column b_1 that will conflict with auto-rename
with pytest.raises(TableMergeError):
table.join(t1, t2, keys='a')