pandas_openscm.db#
Database
Modules:
| Name | Description |
|---|---|
backends |
Available back-ends |
csv |
CSV backend |
deleting |
Functionality for deleting data |
feather |
Feather backend |
in_memory |
In-memory backend |
interfaces |
Interfaces used throughout the db (database) module |
loading |
Loading of data from disk |
netcdf |
netCDF backend |
openscm_db |
Definition of our key OpenSCMDB class |
path_handling |
Functionality for handling paths |
reader |
Database reader |
rewriting |
Functionality for re-writing a database |
saving |
Functionality for saving data |
Classes:
| Name | Description |
|---|---|
AlreadyInDBError |
Raised when saving data would overwrite data which is already in the database |
CSVDataBackend |
CSV data backend |
CSVIndexBackend |
CSV index backend |
EmptyDBError |
Raised when trying to access data from a database that is empty |
FeatherDataBackend |
Feather data backend |
FeatherIndexBackend |
Feather index backend |
InMemoryDataBackend |
In-memory data backend |
InMemoryIndexBackend |
In-memory index backend |
OpenSCMDB |
Database for storing OpenSCM-style data |
OpenSCMDBDataBackend |
Backend for (de-)serialising data |
OpenSCMDBIndexBackend |
Backend for (de-)serialising the index (and file map) |
netCDFDataBackend |
netCDF data backend |
netCDFIndexBackend |
netCDF index backend |
Attributes:
| Name | Type | Description |
|---|---|---|
DATA_BACKENDS |
Inbuilt data back-ends |
|
INDEX_BACKENDS |
Inbuilt index back-ends |
DATA_BACKENDS
module-attribute
#
DATA_BACKENDS = DataBackendOptions(
cast(
tuple[tuple[str, type[OpenSCMDBDataBackend]], ...],
(
("csv", CSVDataBackend),
("feather", FeatherDataBackend),
("in_memory", InMemoryDataBackend),
("netCDF", netCDFDataBackend),
),
)
)
Inbuilt data back-ends
INDEX_BACKENDS
module-attribute
#
INDEX_BACKENDS = IndexBackendOptions(
cast(
tuple[tuple[str, type[OpenSCMDBIndexBackend]], ...],
(
("csv", CSVIndexBackend),
("feather", FeatherIndexBackend),
("in_memory", InMemoryIndexBackend),
("netCDF", netCDFIndexBackend),
),
)
)
Inbuilt index back-ends
AlreadyInDBError #
Bases: ValueError
Raised when saving data would overwrite data which is already in the database
Methods:
| Name | Description |
|---|---|
__init__ |
Initialise the error |
Source code in src/pandas_openscm/db/openscm_db.py
__init__ #
__init__(already_in_db: DataFrame) -> None
Initialise the error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
already_in_db
|
DataFrame
|
data that is already in the database |
required |
Source code in src/pandas_openscm/db/openscm_db.py
CSVDataBackend #
CSV data backend
Methods:
| Name | Description |
|---|---|
load_data |
Load a data file |
save_data |
Save data to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[False]
|
Whether this backend preserves the index of data upon (de-)serialisation |
Source code in src/pandas_openscm/db/csv.py
ext
class-attribute
instance-attribute
#
ext: str = '.csv'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[False]
Whether this backend preserves the index of data upon (de-)serialisation
load_data
staticmethod
#
CSVIndexBackend #
CSV index backend
Methods:
| Name | Description |
|---|---|
load_file_map |
Load the file map |
load_index |
Load the index |
save_file_map |
Save the file map to disk |
save_index |
Save the index to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[False]
|
Whether this backend preserves the |
Source code in src/pandas_openscm/db/csv.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
ext
class-attribute
instance-attribute
#
ext: str = '.csv'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[False]
Whether this backend preserves the pd.MultiIndex upon (de-)serialisation
load_file_map
staticmethod
#
load_index
staticmethod
#
save_file_map
staticmethod
#
Save the file map to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map
|
Series[Path]
|
File map to save |
required |
file_map_file
|
Path
|
File in which to save the file map |
required |
Source code in src/pandas_openscm/db/csv.py
EmptyDBError #
Bases: ValueError
Raised when trying to access data from a database that is empty
Methods:
| Name | Description |
|---|---|
__init__ |
Initialise the error |
Source code in src/pandas_openscm/db/openscm_db.py
FeatherDataBackend #
Feather data backend
For details on feather, see https://arrow.apache.org/docs/python/feather.html
Methods:
| Name | Description |
|---|---|
load_data |
Load a data file |
save_data |
Save data to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[True]
|
Whether this backend preserves the index of data upon (de-)serialisation |
Source code in src/pandas_openscm/db/feather.py
ext
class-attribute
instance-attribute
#
ext: str = '.feather'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[True]
Whether this backend preserves the index of data upon (de-)serialisation
load_data
staticmethod
#
save_data
staticmethod
#
Save data to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to save |
required |
data_file
|
Path
|
File in which to save the data |
required |
Source code in src/pandas_openscm/db/feather.py
FeatherIndexBackend #
Feather index backend
For details on feather, see https://arrow.apache.org/docs/python/feather.html
Methods:
| Name | Description |
|---|---|
load_file_map |
Load the file map |
load_index |
Load the index |
save_file_map |
Save the file map to disk |
save_index |
Save the index to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[True]
|
Whether this backend preserves the |
Source code in src/pandas_openscm/db/feather.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
ext
class-attribute
instance-attribute
#
ext: str = '.feather'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[True]
Whether this backend preserves the pd.MultiIndex upon (de-)serialisation
load_file_map
staticmethod
#
load_index
staticmethod
#
save_file_map
staticmethod
#
Save the file map to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map
|
Series[Path]
|
File map to save |
required |
file_map_file
|
Path
|
File in which to save the file map |
required |
Source code in src/pandas_openscm/db/feather.py
InMemoryDataBackend #
In-memory data backend
Methods:
| Name | Description |
|---|---|
load_data |
Load a data file |
save_data |
Save data to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
data |
dict[str, DataFrame] | None
|
Data store |
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[True]
|
Whether this backend preserves the index of data upon (de-)serialisation |
Source code in src/pandas_openscm/db/in_memory.py
ext
class-attribute
instance-attribute
#
ext: str = '.in-mem'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[True]
Whether this backend preserves the index of data upon (de-)serialisation
load_data #
save_data #
Save data to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to save |
required |
data_file
|
Path
|
File in which to save the data |
required |
Source code in src/pandas_openscm/db/in_memory.py
InMemoryIndexBackend #
In-memory index backend
Methods:
| Name | Description |
|---|---|
load_file_map |
Load the file map |
load_index |
Load the index |
save_file_map |
Save the file map to disk |
save_index |
Save the index to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
file_map |
Series[Path] | None
|
File map store |
index |
DataFrame | None
|
Index store |
preserves_index |
Literal[True]
|
Whether this backend preserves the |
Source code in src/pandas_openscm/db/in_memory.py
79 80 81 82 83 84 85 86 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 172 173 174 175 176 177 178 179 180 181 | |
ext
class-attribute
instance-attribute
#
ext: str = '.in-mem'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[True]
Whether this backend preserves the pd.MultiIndex upon (de-)serialisation
load_file_map #
load_index #
save_file_map #
Save the file map to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map
|
Series[Path]
|
File map to save |
required |
file_map_file
|
Path
|
File in which to save the file map |
required |
Source code in src/pandas_openscm/db/in_memory.py
save_index #
Save the index to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
DataFrame
|
Index to save |
required |
index_file
|
Path
|
File in which to save the index |
required |
Source code in src/pandas_openscm/db/in_memory.py
OpenSCMDB #
Database for storing OpenSCM-style data
This class is focussed on backends that use files as their storage. If you had a different database backend, you might make different choices. We haven't thought through those use cases hence aren't sure how much effort would be required to make something truly backend agnostic.
Methods:
| Name | Description |
|---|---|
create_reader |
Create a database reader |
default_index_file_lock |
Get default lock for the back-end's index file |
delete |
Delete all data in the database |
from_gzipped_tar_archive |
Initialise from a gzipped tar archive |
get_new_data_file_path |
Get the path in which to write a new data file |
load |
Load data |
load_file_map |
Load the file map |
load_index |
Load the index |
load_metadata |
Load the database's metadata |
save |
Save data into the database |
to_gzipped_tar_archive |
Convert to a gzipped tar archive |
Attributes:
| Name | Type | Description |
|---|---|---|
backend_data |
OpenSCMDBDataBackend
|
The backend for (de-)serialising data (from) to disk |
backend_index |
OpenSCMDBIndexBackend
|
The backend for (de-)serialising the database index (from) to disk |
db_dir |
Path
|
Path in which the database is stored |
file_map_file |
Path
|
The file in which the file map is stored |
index_file |
Path
|
The file in which the database's index is stored |
index_file_lock |
BaseFileLock
|
Lock for the index file |
index_file_lock_path |
Path
|
Path to the lock file for the back-end's index file |
is_empty |
bool
|
Whether the database is empty or not |
Source code in src/pandas_openscm/db/openscm_db.py
80 81 82 83 84 85 86 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 172 173 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 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 | |
backend_data
class-attribute
instance-attribute
#
backend_data: OpenSCMDBDataBackend = field(kw_only=True)
The backend for (de-)serialising data (from) to disk
backend_index
class-attribute
instance-attribute
#
backend_index: OpenSCMDBIndexBackend = field(kw_only=True)
The backend for (de-)serialising the database index (from) to disk
db_dir
class-attribute
instance-attribute
#
Path in which the database is stored
Both the index and the data files will be written in this directory.
file_map_file
property
#
file_map_file: Path
The file in which the file map is stored
The file map stores the mapping from file_id to file path.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the file map file |
index_file
property
#
index_file: Path
The file in which the database's index is stored
Returns:
| Type | Description |
|---|---|
Path
|
Path to the index file |
index_file_lock
class-attribute
instance-attribute
#
index_file_lock: BaseFileLock = field(kw_only=True)
Lock for the index file
index_file_lock_path
property
#
index_file_lock_path: Path
Path to the lock file for the back-end's index file
is_empty
property
#
is_empty: bool
Whether the database is empty or not
Returns:
| Type | Description |
|---|---|
bool
|
|
create_reader #
create_reader(
*,
lock: bool | BaseFileLock | None = True,
index_file_lock: BaseFileLock | None = None,
) -> OpenSCMDBReader
Create a database reader
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lock
|
bool | BaseFileLock | None
|
Lock to give to the reader. If If |
True
|
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file Used while loading the index from disk. If not supplied, we use self.index_file_lock. |
None
|
Returns:
| Type | Description |
|---|---|
OpenSCMDBReader
|
Database reader |
Source code in src/pandas_openscm/db/openscm_db.py
default_index_file_lock #
Get default lock for the back-end's index file
Source code in src/pandas_openscm/db/openscm_db.py
delete #
delete(
*,
index_file_lock: BaseFileLock | None = None,
parallel_op_config: ParallelOpConfig | None = None,
progress: bool = False,
max_workers: int | None = None,
) -> None
Delete all data in the database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file If not supplied, we use self.index_file_lock. |
None
|
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.ThreadPoolExecutor with the provided number of workers (a thread pool makes sense as deletion is I/O-bound). If not supplied, the deletions are executed serially. Only used if |
None
|
Source code in src/pandas_openscm/db/openscm_db.py
from_gzipped_tar_archive
classmethod
#
from_gzipped_tar_archive(
tar_archive: Path,
db_dir: Path,
backend_data: OpenSCMDBDataBackend | None = None,
backend_index: OpenSCMDBIndexBackend | None = None,
) -> OpenSCMDB
Initialise from a gzipped tar archive
This also unpacks the files to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tar_archive
|
Path
|
Tar archive from which to initialise |
required |
db_dir
|
Path
|
Directory in which to unpack the database |
required |
backend_data
|
OpenSCMDBDataBackend | None
|
Backend to use for handling the data |
None
|
backend_index
|
OpenSCMDBIndexBackend | None
|
Backend to use for handling the index |
None
|
Returns:
| Type | Description |
|---|---|
OpenSCMDB
|
Initialised database |
Source code in src/pandas_openscm/db/openscm_db.py
get_new_data_file_path #
Get the path in which to write a new data file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
int
|
ID to associate with the file |
required |
Returns:
| Type | Description |
|---|---|
DBPath
|
Information about the path in which to write the new data |
Raises:
| Type | Description |
|---|---|
FileExistsError
|
A file already exists for the given |
Source code in src/pandas_openscm/db/openscm_db.py
load #
load(
selector: Index[Any]
| MultiIndex
| Selector
| None = None,
*,
index_file_lock: BaseFileLock | None = None,
out_columns_type: type | None = None,
out_columns_name: str | None = None,
parallel_op_config: ParallelOpConfig | None = None,
progress: bool = False,
max_workers: int | None = None,
) -> DataFrame
Load data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
selector
|
Index[Any] | MultiIndex | Selector | None
|
Selector to use to choose the data to load |
None
|
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file If not supplied, we use self.index_file_lock. |
None
|
out_columns_type
|
type | None
|
Type to set the output columns to. If not supplied, we don't set the output columns' type. |
None
|
out_columns_name
|
str | None
|
The name for the columns in the output. If not supplied, we don't set the output columns' name. This can also be set with pd.DataFrame.rename_axis but we provide it here for convenience (and in case you couldn't find this trick for ages, like us). |
None
|
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
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded data |
Raises:
| Type | Description |
|---|---|
EmptyDBError
|
The database is empty |
Source code in src/pandas_openscm/db/openscm_db.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
load_file_map #
Load the file map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file If not supplied, we use self.index_file_lock. |
None
|
Returns:
| Type | Description |
|---|---|
Series[Path]
|
Map from file ID to file path |
Raises:
| Type | Description |
|---|---|
EmptyDBError
|
The database is empty |
Source code in src/pandas_openscm/db/openscm_db.py
load_index #
load_index(
*, index_file_lock: BaseFileLock | None = None
) -> DataFrame
Load the index
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file If not supplied, we use self.index_file_lock. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Database index |
Raises:
| Type | Description |
|---|---|
EmptyDBError
|
The database is empty |
Source code in src/pandas_openscm/db/openscm_db.py
load_metadata #
load_metadata(
*, index_file_lock: BaseFileLock | None = None
) -> MultiIndex
Load the database's metadata
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file If not supplied, we use self.index_file_lock. |
None
|
Returns:
| Type | Description |
|---|---|
MultiIndex
|
Loaded metadata |
Source code in src/pandas_openscm/db/openscm_db.py
save #
save(
data: DataFrame,
*,
index_file_lock: BaseFileLock | None = None,
groupby: list[str] | None = None,
allow_overwrite: bool = False,
warn_on_partial_overwrite: bool = True,
progress_grouping: ProgressLike | None = None,
parallel_op_config_save: ParallelOpConfig | None = None,
parallel_op_config_delete: ParallelOpConfig
| None = None,
parallel_op_config_rewrite: ParallelOpConfig
| None = None,
progress: bool = False,
max_workers: int | None = None,
) -> None
Save data into the database
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to add to the database |
required |
index_file_lock
|
BaseFileLock | None
|
Lock for the database's index file If not supplied, we use self.index_file_lock. |
None
|
groupby
|
list[str] | None
|
Metadata columns to use to group the data. If not supplied, we save all the data in a single file. |
None
|
allow_overwrite
|
bool
|
Should overwrites of data that is already in the database be allowed? If this is |
False
|
warn_on_partial_overwrite
|
bool
|
Should a warning be raised if a partial overwrite will occur? This is on by default so that users are warned about the slow operation of re-writing. |
True
|
progress_grouping
|
ProgressLike | None
|
Progress bar to use when grouping the data If not supplied, we use the values of |
None
|
parallel_op_config_save
|
ParallelOpConfig | None
|
Parallel op configuration for executing save operations If not supplied, we use the values of |
None
|
parallel_op_config_delete
|
ParallelOpConfig | None
|
Parallel op configuration for executing any needed delete operations If not supplied, we use the values of |
None
|
parallel_op_config_rewrite
|
ParallelOpConfig | None
|
Parallel op configuration for executing any needed re-write operations If not supplied, we use the values of |
None
|
progress
|
bool
|
Should progress bar(s) be used to display the progress of the various steps? Only used if the corresponding |
False
|
max_workers
|
int | None
|
Maximum number of workers to use for parallel processing. If supplied, we create instances of concurrent.futures.Executor with the provided number of workers (the exact kind of executor depends on the operation). If not supplied, the operations are executed serially. Only used if the corresponding |
None
|
Source code in src/pandas_openscm/db/openscm_db.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 | |
to_gzipped_tar_archive #
Convert to a gzipped tar archive
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_file
|
Path
|
File in which to write the output |
required |
mode
|
Literal['w:gz', 'x:gz']
|
Mode to use to open |
'w:gz'
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the gzipped tar archive This is the same as |
Source code in src/pandas_openscm/db/openscm_db.py
OpenSCMDBDataBackend #
Bases: Protocol
Backend for (de-)serialising data
Designed to be used with OpenSCMDB
Methods:
| Name | Description |
|---|---|
load_data |
Load a data file |
save_data |
Save data to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with data files saved by this backend. |
preserves_index |
bool
|
Whether this backend preserves the index of data upon (de-)serialisation |
Source code in src/pandas_openscm/db/interfaces.py
preserves_index
instance-attribute
#
preserves_index: bool
Whether this backend preserves the index of data upon (de-)serialisation
load_data
staticmethod
#
Load a data file
This is a low-level method that just handles the specifics of loading the data from disk. Working out the path from which to load the data should happen in higher-level functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_file
|
Path
|
File from which to load the data |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded data |
Notes
This just loads the data directly from disk.
If the data had a pd.MultiIndex when it was saved,
this may or not be restored.
It is up to the user
to decide whether to do any pd.MultiIndex restoration or not,
based on their use case and the value of self.preserves_index.
We do not make this choice as converting back to a
pd.MultiIndex can be a very expensive operation,
and we want to give the user control over any such optimisations.
Source code in src/pandas_openscm/db/interfaces.py
save_data
staticmethod
#
Save data to disk
This is a low-level method that just handles the specifics of serialising the data to disk. Working out what to save and in what path should happen in higher-level functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to save |
required |
data_file
|
Path
|
File in which to save the data |
required |
Source code in src/pandas_openscm/db/interfaces.py
OpenSCMDBIndexBackend #
Bases: Protocol
Backend for (de-)serialising the index (and file map)
Designed to be used with OpenSCMDB
Methods:
| Name | Description |
|---|---|
load_file_map |
Load the file map |
load_index |
Load the index |
save_file_map |
Save the file map to disk |
save_index |
Save the index to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with index files saved by this backend. |
preserves_index |
bool
|
Whether this backend preserves the |
Source code in src/pandas_openscm/db/interfaces.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
preserves_index
instance-attribute
#
preserves_index: bool
Whether this backend preserves the pd.MultiIndex upon (de-)serialisation
load_file_map
staticmethod
#
Load the file map
This is a low-level method that just handles the specifics of loading the index from disk. Working out the path from which to load the file map should happen in higher-level functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map_file
|
Path
|
File from which to load the file map |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded file map |
Notes
This returns a pd.DataFrame. It is up to the user to cast this to a pd.Series if they wish.
Source code in src/pandas_openscm/db/interfaces.py
load_index
staticmethod
#
Load the index
This is a low-level method that just handles the specifics of loading the index from disk. Working out the path from which to load the index should happen in higher-level functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file
|
Path
|
File from which to load the index |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded index |
Notes
This just loads the index directly from disk.
If the index had a pd.MultiIndex when it was saved,
this may or not be restored.
It is up to the user
to decide whether to do any pd.MultiIndex restoration or not,
based on their use case and the value of self.preserves_index.
We do not make this choice as converting back to a
pd.MultiIndex can be a very expensive operation,
and we want to give the user control over any such optimisations.
Source code in src/pandas_openscm/db/interfaces.py
save_file_map #
Save the file map to disk
This is a low-level method that just handles the specifics of serialising the file map to disk. Working out what to save and in what path should happen in higher-level functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map
|
Series[Path]
|
File map to save |
required |
file_map_file
|
Path
|
File in which to save the file map |
required |
Source code in src/pandas_openscm/db/interfaces.py
save_index #
Save the index to disk
This is a low-level method that just handles the specifics of serialising the index to disk. Working out what to save and in what path should happen in higher-level functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
DataFrame
|
Index to save |
required |
index_file
|
Path
|
File in which to save the index |
required |
Source code in src/pandas_openscm/db/interfaces.py
netCDFDataBackend #
netCDF data backend
Methods:
| Name | Description |
|---|---|
load_data |
Load a data file |
save_data |
Save data to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[True]
|
Whether this backend preserves the index of data upon (de-)serialisation |
timeseries_dim |
str
|
Name of the timeseries dimension in serialised output |
Source code in src/pandas_openscm/db/netcdf.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 | |
ext
class-attribute
instance-attribute
#
ext: str = '.nc'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[True]
Whether this backend preserves the index of data upon (de-)serialisation
timeseries_dim
class-attribute
instance-attribute
#
timeseries_dim: str = 'ts_id'
Name of the timeseries dimension in serialised output
load_data #
Load a data file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_file
|
Path
|
File from which to load the data |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded data |
Source code in src/pandas_openscm/db/netcdf.py
save_data #
Save data to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to save |
required |
data_file
|
Path
|
File in which to save the data |
required |
Source code in src/pandas_openscm/db/netcdf.py
netCDFIndexBackend #
netCDF index backend
Methods:
| Name | Description |
|---|---|
load_file_map |
Load the database's file map |
load_index |
Load the index |
save_file_map |
Save the file map to disk |
save_index |
Save the index to disk |
Attributes:
| Name | Type | Description |
|---|---|---|
ext |
str
|
Extension to use with files saved by this backend. |
preserves_index |
Literal[True]
|
Whether this backend preserves the |
timeseries_dim |
str
|
Name of the timeseries dimension in serialised output |
Source code in src/pandas_openscm/db/netcdf.py
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 172 173 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 | |
ext
class-attribute
instance-attribute
#
ext: str = '.nc'
Extension to use with files saved by this backend.
preserves_index
property
#
preserves_index: Literal[True]
Whether this backend preserves the pd.MultiIndex upon (de-)serialisation
timeseries_dim
class-attribute
instance-attribute
#
timeseries_dim: str = 'ts_id'
Name of the timeseries dimension in serialised output
load_file_map
staticmethod
#
Load the database's file map
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map_file
|
Path
|
File from which to load the file map |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded file map |
Source code in src/pandas_openscm/db/netcdf.py
load_index
staticmethod
#
Load the index
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_file
|
Path
|
File from which to load the index |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Loaded index |
Source code in src/pandas_openscm/db/netcdf.py
save_file_map
staticmethod
#
Save the file map to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_map
|
Series[Path]
|
File map to save |
required |
file_map_file
|
Path
|
File in which to save the file map |
required |
Source code in src/pandas_openscm/db/netcdf.py
save_index #
Save the index to disk
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
DataFrame
|
Index to save |
required |
index_file
|
Path
|
File in which to save the index |
required |