pandas_openscm.db.rewriting#
Functionality for re-writing a database
Mostly used to make way for new data to be written or to overwrite old data
Classes:
| Name | Description |
|---|---|
MovePlan |
Plan for how to move data to make way for an overwrite |
ReWriteAction |
Description of a re-write action |
Functions:
| Name | Description |
|---|---|
make_move_plan |
Make a plan for moving data around to make room for new data |
rewrite_file |
Re-write a file |
rewrite_files |
Re-write a number of files |
MovePlan #
Plan for how to move data to make way for an overwrite
Attributes:
| Name | Type | Description |
|---|---|---|
delete_paths |
tuple[Path, ...] | None
|
Paths which can be deleted (after the data has been moved) |
moved_file_map |
Series[Path]
|
The file map once all the data has been moved |
moved_index |
DataFrame
|
The index once all the data has been moved |
rewrite_actions |
tuple[ReWriteAction, ...] | None
|
The re-write actions which need to be performed |
Source code in src/pandas_openscm/db/rewriting.py
delete_paths
instance-attribute
#
Paths which can be deleted (after the data has been moved)
moved_file_map
instance-attribute
#
The file map once all the data has been moved
rewrite_actions
instance-attribute
#
rewrite_actions: tuple[ReWriteAction, ...] | None
The re-write actions which need to be performed
ReWriteAction #
make_move_plan #
make_move_plan(
*,
index_start: DataFrame,
file_map_start: Series[Path],
data_to_write: DataFrame,
get_new_data_file_path: Callable[[int], DBPath],
db_dir: Path,
) -> MovePlan
Make a plan for moving data around to make room for new data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_start
|
DataFrame
|
The starting index |
required |
file_map_start
|
Series[Path]
|
The starting file map |
required |
data_to_write
|
DataFrame
|
Data that is going to be written in the database |
required |
get_new_data_file_path
|
Callable[[int], DBPath]
|
Callable which, given an integer, returns the path info for the new data file |
required |
db_dir
|
Path
|
Database directory |
required |
Returns:
| Type | Description |
|---|---|
MovePlan
|
Plan for moving data to make room for the new data |
Source code in src/pandas_openscm/db/rewriting.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
rewrite_file #
rewrite_file(
rewrite_action: ReWriteAction,
backend: OpenSCMDBDataBackend,
) -> None
Re-write a file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rewrite_action
|
ReWriteAction
|
Re-write action to perform |
required |
backend
|
OpenSCMDBDataBackend
|
Back-end to use for reading and writing data |
required |
Source code in src/pandas_openscm/db/rewriting.py
rewrite_files #
rewrite_files(
rewrite_actions: Iterable[ReWriteAction],
backend: OpenSCMDBDataBackend,
parallel_op_config: ParallelOpConfig | None = None,
progress: bool = False,
max_workers: int | None = None,
) -> None
Re-write a number of files
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rewrite_actions
|
Iterable[ReWriteAction]
|
Re-write actions to perform |
required |
backend
|
OpenSCMDBDataBackend
|
Backend to use to load and write the files |
required |
parallel_op_config
|
ParallelOpConfig | None
|
Configuration for executing the operation in parallel with progress bars If not supplied, we use the values of |
None
|
progress
|
bool
|
Should progress bar(s) be used to display the progress of the deletion? Only used if |
False
|
max_workers
|
int | None
|
Maximum number of workers to use for parallel processing. If supplied, we create an instance of
concurrent.futures.ProcessPoolExecutor
with the provided number of workers.
A process pool seems to be the sensible default from our experimentation,
but it is not a universally better choice.
If you need something else because of how your database is set up,
simply pass If not supplied, the loading is executed serially. Only used if |
None
|
Source code in src/pandas_openscm/db/rewriting.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |