series
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| ColumnOp datacook.engine.ops.series The base of all per-column ops: one series per selected column, put back by `assign()`. |
||
| ColumnParams datacook.engine.ops.series Params of a `ColumnOp`: the columns to transform and where results go. |
|
|
| Link datacook.engine.ops.series One link of a method chain: `.name`, `.name(args)` or `[key]`. |
||
| SeriesOp datacook.engine.ops.series A `ColumnOp` that is one call per column, declared like `CallOp`. |
🛈 DocStrings¶
Column-wise ops: one expression per column, generated as a single assign() call.
ColumnOp computes one new series per selected column and writes it back under the same
name (replacing the column) or under <column><suffix>:
df = df.assign(name=df["name"].str.upper(), city=df["city"].str.upper())
SeriesOp derives everything from a declaration of one series call (accessor, method or
function, positional params), like CallOp for frame methods, so execution and generated
code cannot drift. Code recognition uses unchain() (a method chain as a list of links)
and confirms every match by regenerating the code (confirm()).
SELECTION
module-attribute
¶
Params of a ColumnOp that select the columns and name the results.
ColumnOp
¶
Bases: Op
The base of all per-column ops: one series per selected column, put back by assign().
The params select the columns with either columns (a list) or column (one name).
Results replace the columns, or go to <column><suffix> if the params have a suffix
field (ColumnParams has both). Subclasses implement series() (execution), expr()
(its code) and match_expr() (recognise one expression: the column and the other params
as a dict); SeriesOp derives all three from the declaration of one call.
Source code in src/datacook/engine/ops/series.py
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 | |
results
classmethod
¶
Result column per selected column.
selected
classmethod
¶
The selected columns; None = all (only SeriesOp with frame_call).
selection
classmethod
¶
Params selecting columns with suffix; None if the params cannot express it.
Source code in src/datacook/engine/ops/series.py
ColumnParams
¶
Bases: Params
Params of a ColumnOp: the columns to transform and where results go.
Source code in src/datacook/engine/ops/series.py
Link
dataclass
¶
One link of a method chain: .name, .name(args) or [key].
Source code in src/datacook/engine/ops/series.py
literal_args
¶
Literal values of the call's arguments (ValueError if not literal).
Source code in src/datacook/engine/ops/series.py
SeriesOp
¶
Bases: ColumnOp
A ColumnOp that is one call per column, declared like CallOp.
accessor("str","dt","cat"or None) +method:df["a"].str.upper();- or
function(dotted name;pd= pandas):pd.to_datetime(df["a"], ...); method_param: a param whose value picks the method (methodsmaps values to method names, default: the value itself); it is not passed to the call.
Params in positional are passed positionally, the others as keywords when they differ
from their default (or are listed in always). The selection params (columns,
column, suffix) are never passed.
frame_call = True: the method works on a frame column by column (abs, clip,
ffill), so the code calls it once on the selected columns and puts the result back,
out = a.assign(**a[["x", "y"]].clip(lower=0)), or on the whole frame when the
columns field allows None (out = a.ffill()). No accessor, function or suffix then.
Source code in src/datacook/engine/ops/series.py
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 | |
call
classmethod
¶
The declared call on a series (or, with frame_call, a frame).
Source code in src/datacook/engine/ops/series.py
call_code
classmethod
¶
Code of call() on the expression source.
Source code in src/datacook/engine/ops/series.py
assign_code
¶
out = var.assign(a=..., b=...); **{"a b": ...} if a name is no identifier.
Source code in src/datacook/engine/ops/series.py
assigned
¶
(output, input, [(name, value expr), ...]) of an assign_code() statement.
Source code in src/datacook/engine/ops/series.py
chain_column
¶
chain_column(root: expr, links: Sequence[Link], var: str) -> str | None
"a" if a chain from unchain() starts with var["a"].
Source code in src/datacook/engine/ops/series.py
column_of
¶
"a" for var["a"].
Source code in src/datacook/engine/ops/series.py
confirm
¶
confirm(
op: type[Op], params: Params, inputs: Sequence[str], output: str, stmt: stmt
) -> Match | None
A match if the op regenerates exactly stmt from the recognised params.
Source code in src/datacook/engine/ops/series.py
frame_call
¶
frame_call(stmt: stmt, bound: Mapping[str, Any]) -> tuple[str, str, list[str] | None, Link] | None
(output, var, columns, call) of a frame call (SeriesOp.frame_call).
out = var.f(...) (columns None) or out = var.assign(**var[[...]].f(...)).
Source code in src/datacook/engine/ops/series.py
same_code
¶
Whether code (one statement) has the same syntax tree as stmt.
Source code in src/datacook/engine/ops/series.py
unchain
¶
unchain(expr: expr) -> tuple[expr, list[Link]] | None
df["a"].str.upper() -> (Name df, [item "a", attr str, call upper]).
None if a call has *args / **kwargs.