(tempdir)
| 4107 | @pytest.mark.pandas |
| 4108 | @pytest.mark.parquet |
| 4109 | def test_dataset_preserved_partitioning(tempdir): |
| 4110 | # ARROW-8655 |
| 4111 | |
| 4112 | # through discovery, but without partitioning |
| 4113 | _, path = _create_single_file(tempdir) |
| 4114 | dataset = ds.dataset(path) |
| 4115 | assert isinstance(dataset.partitioning, ds.DirectoryPartitioning) |
| 4116 | # TODO(GH-34884) partitioning attribute not preserved in pickling |
| 4117 | # dataset_ = ds.dataset(path) |
| 4118 | # for dataset in [dataset_, pickle_module.loads(pickle_module.dumps(dataset_))]: |
| 4119 | # assert isinstance(dataset.partitioning, ds.DirectoryPartitioning) |
| 4120 | |
| 4121 | # through discovery, with hive partitioning but not specified |
| 4122 | full_table, path = _create_partitioned_dataset(tempdir) |
| 4123 | dataset = ds.dataset(path) |
| 4124 | assert isinstance(dataset.partitioning, ds.DirectoryPartitioning) |
| 4125 | |
| 4126 | # through discovery, with hive partitioning (from a partitioning factory) |
| 4127 | dataset = ds.dataset(path, partitioning="hive") |
| 4128 | part = dataset.partitioning |
| 4129 | assert part is not None |
| 4130 | assert isinstance(part, ds.HivePartitioning) |
| 4131 | assert part.schema == pa.schema([("part", pa.int32())]) |
| 4132 | assert len(part.dictionaries) == 1 |
| 4133 | assert part.dictionaries[0] == pa.array([0, 1, 2], pa.int32()) |
| 4134 | |
| 4135 | # through discovery, with hive partitioning (from a partitioning object) |
| 4136 | part = ds.partitioning(pa.schema([("part", pa.int32())]), flavor="hive") |
| 4137 | assert isinstance(part, ds.HivePartitioning) # not a factory |
| 4138 | assert len(part.dictionaries) == 1 |
| 4139 | assert all(x is None for x in part.dictionaries) |
| 4140 | dataset = ds.dataset(path, partitioning=part) |
| 4141 | part = dataset.partitioning |
| 4142 | assert isinstance(part, ds.HivePartitioning) |
| 4143 | assert part.schema == pa.schema([("part", pa.int32())]) |
| 4144 | # TODO is this expected? |
| 4145 | assert len(part.dictionaries) == 1 |
| 4146 | assert all(x is None for x in part.dictionaries) |
| 4147 | |
| 4148 | # through manual creation -> not available |
| 4149 | dataset = ds.dataset(path, partitioning="hive") |
| 4150 | dataset2 = ds.FileSystemDataset( |
| 4151 | list(dataset.get_fragments()), schema=dataset.schema, |
| 4152 | format=dataset.format, filesystem=dataset.filesystem |
| 4153 | ) |
| 4154 | assert dataset2.partitioning is None |
| 4155 | |
| 4156 | # through discovery with ParquetDatasetFactory |
| 4157 | root_path = tempdir / "data-partitioned-metadata" |
| 4158 | metadata_path, _ = _create_parquet_dataset_partitioned(root_path) |
| 4159 | dataset = ds.parquet_dataset(metadata_path, partitioning="hive") |
| 4160 | part = dataset.partitioning |
| 4161 | assert part is not None |
| 4162 | assert isinstance(part, ds.HivePartitioning) |
| 4163 | assert part.schema == pa.schema([("part", pa.string())]) |
| 4164 | assert len(part.dictionaries) == 1 |
| 4165 | # will be fixed by ARROW-13153 (order is not preserved at the moment) |
| 4166 | # assert part.dictionaries[0] == pa.array(["a", "b"], pa.string()) |
nothing calls this directly
no test coverage detected