Tabbing
tabbed.tabbing
Tab instances are callables that return a boolean for a single row dictionary to indicate if the row should be accepted or rejected. This module has equality, membership, regular expression, rich comparison and custom callable Tabs. The Tabulator is the client facing interface for building Tab instances. It allows for Tab instances to be constructed from keyword arguments.
tabbed.tabbing.Tabulator
Bases: ReprMixin
A Callable for creating, storing & applying Tabs to a row dictionary.
Tablulators are the interface that should be used to create Tab instances. They allow Tabs to be constructed from keyword arguments and apply multiple Tabs sequentially to a row dictionary of file data. If columns from the file are provided, the Tabulator will restrict which columns of the row dictionary will be returned.
Attributes:
Name | Type | Description |
---|---|---|
header |
A Header instance storing all column names of a file. |
|
tabs |
A list of tab instances to apply to each row. |
|
columns |
Columns to extract from each row as a list of column names, a list of integer column indices or a single re pattern to match column names against. |
Examples:
Source code in src/tabbed/tabbing.py
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 |
|
__init__(header, tabs=None, columns=None)
Initialize with tabs, columns to extract & Header instance.
Source code in src/tabbed/tabbing.py
from_keywords(header, columns=None, **kwargs)
classmethod
Alternative instance constructor using keyword args to define Tabs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header
|
Header
|
A Header type containing the names of all the columns in infile. |
required |
columns
|
Optional[List[str] | List[int] | Pattern]
|
Columns to extract from each row as a list of column names, a list of integer column indices or a single re pattern to match column names against. |
None
|
kwargs
|
CellType | Sequence[CellType] | Pattern | Callable[[Dict[str, CellType], str], bool]
|
A mapping of column names and values to convert to Tab instances (e.g. 'group' = ['a', 'b'], 'count' = '<=20', ...) |
{}
|
Returns:
Type | Description |
---|---|
Self
|
A Tabulator instance |
Source code in src/tabbed/tabbing.py
__call__(row)
Apply Tab instances and column filter to this row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Dict[str, CellType]
|
A row dictionary of a file whose values have been type casted. |
required |
Returns:
Type | Description |
---|---|
Dict[str, CellType] | None
|
A row dictionary or None if row does not satisfy all tabs. |
Source code in src/tabbed/tabbing.py
TABS
tabbed.tabbing.Equality
Bases: Tab
A Tab to test if a value in a row dictionary equals another value.
Attributes:
Name | Type | Description |
---|---|---|
name |
The item name in row dictionary whose value will be compared. |
|
matching |
The value to compare against the named item in row dictionary. |
Examples:
Source code in src/tabbed/tabbing.py
__init__(name, matching)
__call__(row)
Apply this tab to a row dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Dict[str, CellType]
|
A row dictionary of a file whose values have been type casted. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if row's named value equals matching value and False otherwise. |
Source code in src/tabbed/tabbing.py
tabbed.tabbing.Membership
Bases: Tab
A Tab to test if a value in a row dictionary is a member of a collection.
Attributes:
Name | Type | Description |
---|---|---|
name |
The named value in row dict. to be member tested against collection. |
|
collection |
A sequence of items for testing membership. |
Examples:
Source code in src/tabbed/tabbing.py
__init__(name, collection)
__call__(row)
Apply this tab to a row dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Dict[str, CellType]
|
A row dictionary of a file whose values have been type casted. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if named value in row is in collection. |
Source code in src/tabbed/tabbing.py
tabbed.tabbing.Regex
Bases: Tab
A Tab to test a compiled re pattern against a string value in a row dict.
Attributes:
Name | Type | Description |
---|---|---|
name |
The named value in row dictionary to be pattern tested. |
|
pattern |
A compiled regular expression pattern (see re.compile). |
Examples:
Source code in src/tabbed/tabbing.py
__init__(name, pattern)
__call__(row)
Apply this tab to a row dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Dict[str, CellType]
|
A row dictionary of a file whose values have been type casted. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if pattern is found in named value of row & False otherwise. |
Source code in src/tabbed/tabbing.py
tabbed.tabbing.Comparison
Bases: Tab
A Tab to test if named value in a row dictionary satisfies a comparison.
Attributes:
Name | Type | Description |
---|---|---|
name |
The named value in row dictionary to compare. |
|
comparison |
A string containing one or two rich comparison operators followed by a Comparable type (e.g. '>= 8.3', '< 9 and > 2'). The logical 'and' or 'or' may be used for double comparisons. |
|
permissive |
A boolean indicating whether comparisons between mismatched types should result in the row being accepted (True) or rejected (False). For example if row[name] = '-' and comparison requires row[name]
|
Examples:
Source code in src/tabbed/tabbing.py
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 |
|
__init__(name, comparison, permissive=True)
Initialize this tab instance.
Source code in src/tabbed/tabbing.py
__call__(row)
Apply this tab to a row dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Dict[str, CellType]
|
A row dictionary of a file whose values have been type casted. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if named value satisfies the comparison(s). |
Raises:
Type | Description |
---|---|
ValueError
|
is issued if more than two logicals are in comparison. |
Source code in src/tabbed/tabbing.py
tabbed.tabbing.Calling
Bases: Tab
A Tab to test if named value in a row satisfies a boolean function.
Attributes:
Name | Type | Description |
---|---|---|
name |
The name of the row dictionary item to supply to func. |
|
func |
A boolean returning callable that accepts a row, a name and any required kwargs in that order. |
Examples:
Source code in src/tabbed/tabbing.py
__init__(name, func, **kwargs)
Initialize this tab instance.
__call__(row)
Apply this tab to a row dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
row
|
Dict[str, CellType]
|
A row dictionary of a file whose values have been type casted. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if func returns True for this row and False otherwise. |
Source code in src/tabbed/tabbing.py
tabbed.tabbing.Accepting
Bases: Tab
A Tab that returns True for any row dictionary.
This Tab defines what to do with a row when no tabs are present.
Examples: