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


Python validator.SchemaValidator类代码示例

本文整理汇总了Python中pysemantic.validator.SchemaValidator的典型用法代码示例。如果您正苦于以下问题:Python SchemaValidator类的具体用法?Python SchemaValidator怎么用?Python SchemaValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_converter

 def test_converter(self):
     """Test if the SeriesValidator properly applies converters."""
     schema = deepcopy(self.basespecs['iris'])
     schema['converters'] = {'Sepal Width': lambda x: int(float(x))}
     validator = SchemaValidator(specification=schema)
     filtered = pd.read_csv(**validator.get_parser_args())['Sepal Width']
     self.assertTrue(filtered.dtype == np.int)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:7,代码来源:test_validator.py

示例2: test_multifile_dataset_schema

    def test_multifile_dataset_schema(self):
        """Test if a dataset schema with multiple files works properly."""
        duplicate_iris_path = self.basespecs['iris']['path'].replace("iris",
                                                                     "iris2")
        # Copy the file
        dframe = pd.read_csv(self.basespecs['iris']['path'])
        dframe.to_csv(duplicate_iris_path, index=False)

        # Create the news chema
        schema = {'nrows': [150, 150], 'path': [duplicate_iris_path,
                  self.basespecs['iris']['path']]}
        for key, value in self.basespecs['iris'].iteritems():
            if key not in schema:
                schema[key] = value

        try:
            validator = SchemaValidator(specification=schema)
            self.assertTrue(validator.is_multifile)
            self.assertItemsEqual(validator.filepath, schema['path'])
            self.assertItemsEqual(validator.nrows, schema['nrows'])
            validated_args = validator.get_parser_args()
            self.assertTrue(isinstance(validated_args, list))
            self.assertEqual(len(validated_args), 2)
        finally:
            os.unlink(duplicate_iris_path)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:25,代码来源:test_validator.py

示例3: test_exclude_columns

 def test_exclude_columns(self):
     schema = deepcopy(self.basespecs['iris'])
     schema['exclude_columns'] = ['Sepal Length', 'Petal Width']
     validator = SchemaValidator(specification=schema)
     loaded = pd.read_csv(**validator.get_parser_args())
     self.assertItemsEqual(loaded.columns,
                           ['Petal Length', 'Sepal Width', 'Species'])
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:7,代码来源:test_validator.py

示例4: test_header

 def test_header(self):
     """Test if the header option works."""
     schema = deepcopy(self.basespecs['iris'])
     schema['header'] = 1
     validator = SchemaValidator(specification=schema)
     loaded = pd.read_csv(**validator.get_parser_args())
     self.assertItemsEqual(loaded.columns,
                           ['5.1', '3.5', '1.4', '0.2', 'setosa'])
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:8,代码来源:test_validator.py

示例5: test_validator_specfile_name_iris

 def test_validator_specfile_name_iris(self):
     """Test if the validator works when providing specifle and name for the
     iris dataset.
     """
     validator = SchemaValidator(specfile=self.specfile, name="iris")
     validated_parser_args = validator.get_parser_args()
     self.assertKwargsEqual(validated_parser_args,
                            self.ideal_iris_parser_args)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:8,代码来源:test_validator.py

示例6: test_random_rows_selection

 def test_random_rows_selection(self):
     """Test if the validator correctly produces the function argument
     required for selecting a range of rows from a dataset."""
     self.basespecs['iris']['nrows'] = {'range': [25, 75]}
     validator = SchemaValidator(specification=self.basespecs['iris'])
     parser_args = validator.get_parser_args()
     self.assertEqual(parser_args['skiprows'], 25)
     self.assertEqual(parser_args['nrows'], 50)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:8,代码来源:test_validator.py

示例7: test_index

 def test_index(self):
     """Test if specifying the index_col works."""
     specs = deepcopy(self.basespecs['iris'])
     index_col = "Species"
     specs['index_col'] = index_col
     validator = SchemaValidator(specification=specs)
     parser_args = validator.get_parser_args()
     self.assertItemsEqual(parser_args['index_col'], index_col)
开发者ID:prolificd,项目名称:pysemantic,代码行数:8,代码来源:test_validator.py

示例8: test_colnames_as_callable

 def test_colnames_as_callable(self):
     """Test if column names work when specified as a callable."""
     schema = deepcopy(self.basespecs['iris'])
     translator = lambda x: "_".join([s.lower() for s in x.split()])
     schema['column_names'] = translator
     ideal = {'column_names': translator}
     validator = SchemaValidator(specification=schema)
     validator.get_parser_args()
     self.assertKwargsEqual(validator.df_rules, ideal)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例9: test_multiindex

 def test_multiindex(self):
     """Test if validator accepts list of index columns for
     multiindexing."""
     specs = deepcopy(self.basespecs['person_activity'])
     index_cols = ['tag', 'sequence_name']
     specs['index_col'] = index_cols
     validator = SchemaValidator(specification=specs)
     parser_args = validator.get_parser_args()
     self.assertItemsEqual(parser_args['index_col'], index_cols)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例10: test_from_dict

 def test_from_dict(self):
     """Test if the SchemaValidator.from_dict constructor works."""
     validator = SchemaValidator.from_dict(self.basespecs['iris'])
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_iris_parser_args)
     validator = SchemaValidator.from_dict(self.basespecs[
                                                         'person_activity'])
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_activity_parser_args)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例11: test_colnames_as_list

 def test_colnames_as_list(self):
     """Test if the column names option works when provided as a list."""
     schema = deepcopy(self.basespecs['iris'])
     schema['header'] = 0
     ideal = ['a', 'b', 'c', 'd', 'e']
     schema['column_names'] = ideal
     validator = SchemaValidator(specification=schema)
     loaded = pd.read_csv(**validator.get_parser_args())
     self.assertItemsEqual(loaded.columns, ideal)
开发者ID:prolificd,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例12: test_validator_specfile_name_activity

 def test_validator_specfile_name_activity(self):
     """Test if the validator works when providing specifle and name for the
     activity dataset.
     """
     validator = SchemaValidator(specfile=self.specfile,
                                 name="person_activity")
     validated_parser_args = validator.get_parser_args()
     self.assertKwargsEqual(validated_parser_args,
                            self.ideal_activity_parser_args)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例13: test_from_specfile

 def test_from_specfile(self):
     """Test if the SchemaValidator.from_specfile constructor works."""
     validator = SchemaValidator.from_specfile(self.specfile, "iris")
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_iris_parser_args)
     validator = SchemaValidator.from_specfile(self.specfile,
                                               "person_activity")
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_activity_parser_args)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例14: test_validator_with_specdict_iris

 def test_validator_with_specdict_iris(self):
     """Check if the validator works when only the specification is supplied
     as a dictionary for the iris dataset.
     """
     validator = SchemaValidator(specification=self.basespecs['iris'])
     self.assertFalse(validator.is_multifile)
     validated_parser_args = validator.get_parser_args()
     self.assertKwargsEqual(validated_parser_args,
                            self.ideal_iris_parser_args)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py

示例15: test_to_dict

 def test_to_dict(self):
     """Test if the SchemaValidator.to_dict method works."""
     validator = SchemaValidator(specification=self.basespecs['iris'])
     self.assertKwargsEqual(validator.to_dict(),
                            self.ideal_iris_parser_args)
     validator = SchemaValidator(specification=self.basespecs[
                                                         'person_activity'])
     self.assertKwargsEqual(validator.to_dict(),
                            self.ideal_activity_parser_args)
开发者ID:abhishekarora12,项目名称:pysemantic,代码行数:9,代码来源:test_validator.py


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