(pickle_module)
| 299 | |
| 300 | |
| 301 | def test_convert_options(pickle_module): |
| 302 | cls = ConvertOptions |
| 303 | opts = cls() |
| 304 | |
| 305 | check_options_class( |
| 306 | cls, check_utf8=[True, False], |
| 307 | strings_can_be_null=[False, True], |
| 308 | quoted_strings_can_be_null=[True, False], |
| 309 | decimal_point=['.', ','], |
| 310 | include_columns=[[], ['def', 'abc']], |
| 311 | include_missing_columns=[False, True], |
| 312 | auto_dict_encode=[False, True], |
| 313 | timestamp_parsers=[[], [ISO8601, '%y-%m']]) |
| 314 | |
| 315 | check_options_class_pickling( |
| 316 | cls, pickler=pickle_module, |
| 317 | check_utf8=False, |
| 318 | strings_can_be_null=True, |
| 319 | quoted_strings_can_be_null=False, |
| 320 | decimal_point=',', |
| 321 | include_columns=['def', 'abc'], |
| 322 | include_missing_columns=False, |
| 323 | auto_dict_encode=True, |
| 324 | timestamp_parsers=[ISO8601, '%y-%m'], |
| 325 | default_column_type=pa.int16()) |
| 326 | |
| 327 | with pytest.raises(ValueError): |
| 328 | opts.decimal_point = '..' |
| 329 | |
| 330 | assert opts.auto_dict_max_cardinality > 0 |
| 331 | opts.auto_dict_max_cardinality = 99999 |
| 332 | assert opts.auto_dict_max_cardinality == 99999 |
| 333 | |
| 334 | assert opts.column_types == {} |
| 335 | # Pass column_types as mapping |
| 336 | opts.column_types = {'b': pa.int16(), 'c': pa.float32()} |
| 337 | assert opts.column_types == {'b': pa.int16(), 'c': pa.float32()} |
| 338 | opts.column_types = {'v': 'int16', 'w': 'null'} |
| 339 | assert opts.column_types == {'v': pa.int16(), 'w': pa.null()} |
| 340 | # Pass column_types as schema |
| 341 | schema = pa.schema([('a', pa.int32()), ('b', pa.string())]) |
| 342 | opts.column_types = schema |
| 343 | assert opts.column_types == {'a': pa.int32(), 'b': pa.string()} |
| 344 | # Pass column_types as sequence |
| 345 | opts.column_types = [('x', pa.binary())] |
| 346 | assert opts.column_types == {'x': pa.binary()} |
| 347 | |
| 348 | with pytest.raises(TypeError, match='DataType expected'): |
| 349 | opts.column_types = {'a': None} |
| 350 | with pytest.raises(TypeError): |
| 351 | opts.column_types = 0 |
| 352 | |
| 353 | assert opts.default_column_type is None |
| 354 | opts.default_column_type = pa.string() |
| 355 | assert opts.default_column_type == pa.string() |
| 356 | opts.default_column_type = 'int32' |
| 357 | assert opts.default_column_type == pa.int32() |
| 358 | opts.default_column_type = None |
nothing calls this directly
no test coverage detected