當前位置: 首頁>>代碼示例>>Python>>正文


Python table.join方法代碼示例

本文整理匯總了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']) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:23,代碼來源:test_operations.py

示例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']) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:21,代碼來源:test_operations.py

示例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') 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:22,代碼來源:test_operations.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:22,代碼來源:test_operations.py

示例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)) 
開發者ID:KeplerGO,項目名稱:lightkurve,代碼行數:8,代碼來源:search.py

示例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 
開發者ID:KeplerGO,項目名稱:lightkurve,代碼行數:29,代碼來源:search.py

示例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 
開發者ID:zooniverse,項目名稱:Data-digging,代碼行數:15,代碼來源:gz_reduce.py

示例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) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:11,代碼來源:test_common.py

示例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' 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:17,代碼來源:test_mixin.py

示例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 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:6,代碼來源:test_operations.py

示例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') 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:28,代碼來源:test_operations.py

示例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']) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:38,代碼來源:test_operations.py

示例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  --']) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:34,代碼來源:test_operations.py

示例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'] 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:13,代碼來源:test_operations.py

示例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') 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:13,代碼來源:test_operations.py


注:本文中的astropy.table.join方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。