当前位置: 首页>>代码示例>>Python>>正文


Python errors.MergeError方法代码示例

本文整理汇总了Python中pandas.errors.MergeError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.MergeError方法的具体用法?Python errors.MergeError怎么用?Python errors.MergeError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.errors的用法示例。


在下文中一共展示了errors.MergeError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_star_schema_dataframe

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _get_star_schema_dataframe(dataframes, mdx_engine):
    """Merge all DataFrames as star schema.

    :return: star schema DataFrame
    """

    fusion = dataframes[mdx_engine.facts]
    for df in dataframes.values():
        try:
            fusion = fusion.merge(df)
        except MergeError:
            print("No common column")

    star_schema_df = mdx_engine.clean_data(fusion, mdx_engine.measures)

    return star_schema_df[[col for col in fusion.columns if col.lower()[-3:] != "_id"]] 
开发者ID:abilian,项目名称:olapy,代码行数:18,代码来源:utils.py

示例2: construct_star_schema

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def construct_star_schema(self, facts):
        """Construct star schema DataFrame from csv files.

        :param facts: Facts table name
        :return: star schema DataFrame
        """
        # loading facts table
        df = pd.read_csv(os.path.join(self.cube_path, facts + ".csv"), sep=self.sep)
        for file_name in os.listdir(self.cube_path):
            try:
                df = df.merge(
                    pd.read_csv(os.path.join(self.cube_path, file_name), sep=self.sep)
                )
            except MergeError:
                print("No common column")

        return df 
开发者ID:abilian,项目名称:olapy,代码行数:19,代码来源:cube_loader.py

示例3: _get_cython_type

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _get_cython_type(dtype):
    """ Given a dtype, return a C name like 'int64_t' or 'double' """
    type_name = _get_dtype(dtype).name
    ctype = _cython_types.get(type_name, 'object')
    if ctype == 'error':
        raise MergeError('unsupported type: {type}'.format(type=type_name))
    return ctype 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:merge.py

示例4: construct_star_schema

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def construct_star_schema(self, facts):
        # type: (Text) -> pd.DataFrame
        """Construct star schema DataFrame from database.

        :param facts: Facts table name
        :return: star schema DataFrame
        """

        df = psql.read_sql_query("SELECT * FROM {}".format(facts), self.sqla_engine)
        inspector = inspect(self.sqla_engine)

        for db_table_name in inspector.get_table_names():
            # try:
            #     db_table_name = str(db_table_name)
            # except Exception:
            #     if isinstance(db_table_name, Iterable):
            #         db_table_name = db_table_name[0]
            try:
                df = df.merge(
                    psql.read_sql_query(
                        "SELECT * FROM {}".format(db_table_name), self.sqla_engine
                    )
                )
            except MergeError:
                print("No common column between {} and {}".format(facts, db_table_name))

        return df 
开发者ID:abilian,项目名称:olapy,代码行数:29,代码来源:cube_loader_db.py

示例5: _validate_specification

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _validate_specification(self):
        # Hm, any way to make this logic less complicated??
        if self.on is None and self.left_on is None and self.right_on is None:

            if self.left_index and self.right_index:
                self.left_on, self.right_on = (), ()
            elif self.left_index:
                if self.right_on is None:
                    raise MergeError('Must pass right_on or right_index=True')
            elif self.right_index:
                if self.left_on is None:
                    raise MergeError('Must pass left_on or left_index=True')
            else:
                # use the common columns
                common_cols = self.left.columns.intersection(
                    self.right.columns)
                if len(common_cols) == 0:
                    raise MergeError(
                        'No common columns to perform merge on. '
                        'Merge options: left_on={lon}, right_on={ron}, '
                        'left_index={lidx}, right_index={ridx}'
                        .format(lon=self.left_on, ron=self.right_on,
                                lidx=self.left_index, ridx=self.right_index))
                if not common_cols.is_unique:
                    raise MergeError("Data columns not unique: {common!r}"
                                     .format(common=common_cols))
                self.left_on = self.right_on = common_cols
        elif self.on is not None:
            if self.left_on is not None or self.right_on is not None:
                raise MergeError('Can only pass argument "on" OR "left_on" '
                                 'and "right_on", not a combination of both.')
            self.left_on = self.right_on = self.on
        elif self.left_on is not None:
            n = len(self.left_on)
            if self.right_index:
                if len(self.left_on) != self.right.index.nlevels:
                    raise ValueError('len(left_on) must equal the number '
                                     'of levels in the index of "right"')
                self.right_on = [None] * n
        elif self.right_on is not None:
            n = len(self.right_on)
            if self.left_index:
                if len(self.right_on) != self.left.index.nlevels:
                    raise ValueError('len(right_on) must equal the number '
                                     'of levels in the index of "left"')
                self.left_on = [None] * n
        if len(self.right_on) != len(self.left_on):
            raise ValueError("len(right_on) must equal len(left_on)") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:50,代码来源:merge.py

示例6: _validate

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _validate(self, validate):

        # Check uniqueness of each
        if self.left_index:
            left_unique = self.orig_left.index.is_unique
        else:
            left_unique = MultiIndex.from_arrays(self.left_join_keys
                                                 ).is_unique

        if self.right_index:
            right_unique = self.orig_right.index.is_unique
        else:
            right_unique = MultiIndex.from_arrays(self.right_join_keys
                                                  ).is_unique

        # Check data integrity
        if validate in ["one_to_one", "1:1"]:
            if not left_unique and not right_unique:
                raise MergeError("Merge keys are not unique in either left"
                                 " or right dataset; not a one-to-one merge")
            elif not left_unique:
                raise MergeError("Merge keys are not unique in left dataset;"
                                 " not a one-to-one merge")
            elif not right_unique:
                raise MergeError("Merge keys are not unique in right dataset;"
                                 " not a one-to-one merge")

        elif validate in ["one_to_many", "1:m"]:
            if not left_unique:
                raise MergeError("Merge keys are not unique in left dataset;"
                                 " not a one-to-many merge")

        elif validate in ["many_to_one", "m:1"]:
            if not right_unique:
                raise MergeError("Merge keys are not unique in right dataset;"
                                 " not a many-to-one merge")

        elif validate in ['many_to_many', 'm:m']:
            pass

        else:
            raise ValueError("Not a valid argument for validate") 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:44,代码来源:merge.py

示例7: _get_merge_keys

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _get_merge_keys(self):

        # note this function has side effects
        (left_join_keys,
         right_join_keys,
         join_names) = super(_AsOfMerge, self)._get_merge_keys()

        # validate index types are the same
        for i, (lk, rk) in enumerate(zip(left_join_keys, right_join_keys)):
            if not is_dtype_equal(lk.dtype, rk.dtype):
                raise MergeError("incompatible merge keys [{i}] {lkdtype} and "
                                 "{rkdtype}, must be the same type"
                                 .format(i=i, lkdtype=lk.dtype,
                                         rkdtype=rk.dtype))

        # validate tolerance; must be a Timedelta if we have a DTI
        if self.tolerance is not None:

            if self.left_index:
                lt = self.left.index
            else:
                lt = left_join_keys[-1]

            msg = ("incompatible tolerance {tolerance}, must be compat "
                   "with type {lkdtype}".format(
                       tolerance=type(self.tolerance),
                       lkdtype=lt.dtype))

            if is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt):
                if not isinstance(self.tolerance, Timedelta):
                    raise MergeError(msg)
                if self.tolerance < Timedelta(0):
                    raise MergeError("tolerance must be positive")

            elif is_int64_dtype(lt):
                if not is_integer(self.tolerance):
                    raise MergeError(msg)
                if self.tolerance < 0:
                    raise MergeError("tolerance must be positive")

            elif is_float_dtype(lt):
                if not is_number(self.tolerance):
                    raise MergeError(msg)
                if self.tolerance < 0:
                    raise MergeError("tolerance must be positive")

            else:
                raise MergeError("key must be integer, timestamp or float")

        # validate allow_exact_matches
        if not is_bool(self.allow_exact_matches):
            msg = "allow_exact_matches must be boolean, passed {passed}"
            raise MergeError(msg.format(passed=self.allow_exact_matches))

        return left_join_keys, right_join_keys, join_names 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:57,代码来源:merge.py

示例8: _validate

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _validate(self, validate):

        # Check uniqueness of each
        if self.left_index:
            left_unique = self.orig_left.index.is_unique
        else:
            left_unique = MultiIndex.from_arrays(self.left_join_keys
                                                 ).is_unique

        if self.right_index:
            right_unique = self.orig_right.index.is_unique
        else:
            right_unique = MultiIndex.from_arrays(self.right_join_keys
                                                  ).is_unique

        # Check data integrity
        if validate in ["one_to_one", "1:1"]:
            if not left_unique and not right_unique:
                raise MergeError("Merge keys are not unique in either left"
                                 " or right dataset; not a one-to-one merge")
            elif not left_unique:
                raise MergeError("Merge keys are not unique in left dataset;"
                                 " not a one-to-one merge")
            elif not right_unique:
                raise MergeError("Merge keys are not unique in right dataset;"
                                 " not a one-to-one merge")

        elif validate in ["one_to_many", "1:m"]:
            if not left_unique:
                raise MergeError("Merge keys are not unique in left dataset;"
                                 "not a one-to-many merge")

        elif validate in ["many_to_one", "m:1"]:
            if not right_unique:
                raise MergeError("Merge keys are not unique in right dataset;"
                                 " not a many-to-one merge")

        elif validate in ['many_to_many', 'm:m']:
            pass

        else:
            raise ValueError("Not a valid argument for validate") 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:44,代码来源:merge.py

示例9: _get_merge_keys

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _get_merge_keys(self):

        # note this function has side effects
        (left_join_keys,
         right_join_keys,
         join_names) = super(_AsOfMerge, self)._get_merge_keys()

        # validate index types are the same
        for i, (lk, rk) in enumerate(zip(left_join_keys, right_join_keys)):
            if not is_dtype_equal(lk.dtype, rk.dtype):
                raise MergeError("incompatible merge keys [{i}] {lkdtype} and "
                                 "{rkdtype}, must be the same type"
                                 .format(i=i, lkdtype=lk.dtype,
                                         rkdtype=rk.dtype))

        # validate tolerance; must be a Timedelta if we have a DTI
        if self.tolerance is not None:

            if self.left_index:
                lt = self.left.index
            else:
                lt = left_join_keys[-1]

            msg = ("incompatible tolerance {tolerance}, must be compat "
                   "with type {lkdtype}".format(
                       tolerance=type(self.tolerance),
                       lkdtype=lt.dtype))

            if is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt):
                if not isinstance(self.tolerance, Timedelta):
                    raise MergeError(msg)
                if self.tolerance < Timedelta(0):
                    raise MergeError("tolerance must be positive")

            elif is_int64_dtype(lt):
                if not is_integer(self.tolerance):
                    raise MergeError(msg)
                if self.tolerance < 0:
                    raise MergeError("tolerance must be positive")

            else:
                raise MergeError("key must be integer or timestamp")

        # validate allow_exact_matches
        if not is_bool(self.allow_exact_matches):
            msg = "allow_exact_matches must be boolean, passed {passed}"
            raise MergeError(msg.format(passed=self.allow_exact_matches))

        return left_join_keys, right_join_keys, join_names 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:51,代码来源:merge.py

示例10: _validate_specification

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _validate_specification(self):
        # Hm, any way to make this logic less complicated??
        if self.on is None and self.left_on is None and self.right_on is None:

            if self.left_index and self.right_index:
                self.left_on, self.right_on = (), ()
            elif self.left_index:
                if self.right_on is None:
                    raise MergeError('Must pass right_on or right_index=True')
            elif self.right_index:
                if self.left_on is None:
                    raise MergeError('Must pass left_on or left_index=True')
            else:
                # use the common columns
                common_cols = self.left.columns.intersection(
                    self.right.columns)
                if len(common_cols) == 0:
                    raise MergeError('No common columns to perform merge on')
                if not common_cols.is_unique:
                    raise MergeError("Data columns not unique: {common!r}"
                                     .format(common=common_cols))
                self.left_on = self.right_on = common_cols
        elif self.on is not None:
            if self.left_on is not None or self.right_on is not None:
                raise MergeError('Can only pass argument "on" OR "left_on" '
                                 'and "right_on", not a combination of both.')
            self.left_on = self.right_on = self.on
        elif self.left_on is not None:
            n = len(self.left_on)
            if self.right_index:
                if len(self.left_on) != self.right.index.nlevels:
                    raise ValueError('len(left_on) must equal the number '
                                     'of levels in the index of "right"')
                self.right_on = [None] * n
        elif self.right_on is not None:
            n = len(self.right_on)
            if self.left_index:
                if len(self.right_on) != self.left.index.nlevels:
                    raise ValueError('len(right_on) must equal the number '
                                     'of levels in the index of "left"')
                self.left_on = [None] * n
        if len(self.right_on) != len(self.left_on):
            raise ValueError("len(right_on) must equal len(left_on)") 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:45,代码来源:merge.py

示例11: _get_merge_keys

# 需要导入模块: from pandas import errors [as 别名]
# 或者: from pandas.errors import MergeError [as 别名]
def _get_merge_keys(self):

        # note this function has side effects
        (left_join_keys,
         right_join_keys,
         join_names) = super(_AsOfMerge, self)._get_merge_keys()

        # validate index types are the same
        for lk, rk in zip(left_join_keys, right_join_keys):
            if not is_dtype_equal(lk.dtype, rk.dtype):
                raise MergeError("incompatible merge keys, "
                                 "must be the same type")

        # validate tolerance; must be a Timedelta if we have a DTI
        if self.tolerance is not None:

            if self.left_index:
                lt = self.left.index
            else:
                lt = left_join_keys[-1]

            msg = "incompatible tolerance, must be compat " \
                  "with type {lt}".format(lt=type(lt))

            if is_datetime64_dtype(lt) or is_datetime64tz_dtype(lt):
                if not isinstance(self.tolerance, Timedelta):
                    raise MergeError(msg)
                if self.tolerance < Timedelta(0):
                    raise MergeError("tolerance must be positive")

            elif is_int64_dtype(lt):
                if not is_integer(self.tolerance):
                    raise MergeError(msg)
                if self.tolerance < 0:
                    raise MergeError("tolerance must be positive")

            else:
                raise MergeError("key must be integer or timestamp")

        # validate allow_exact_matches
        if not is_bool(self.allow_exact_matches):
            msg = "allow_exact_matches must be boolean, passed {passed}"
            raise MergeError(msg.format(passed=self.allow_exact_matches))

        return left_join_keys, right_join_keys, join_names 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:47,代码来源:merge.py


注:本文中的pandas.errors.MergeError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。