MCPcopy
hub / github.com/pathwaycom/pathway / count

Method count

python/pathway/internals/expressions/string.py:473–524  ·  view source on GitHub ↗

Returns the number of non-overlapping occurrences of substring sub in the range [start, end). Optional arguments start and end are interpreted as in slice notation. Example: >>> import pathway as pw >>> table = pw.debug.table_from_markdown( ... '''

(
        self,
        sub: expr.ColumnExpression | str,
        start: expr.ColumnExpression | int | None = None,
        end: expr.ColumnExpression | int | None = None,
    )

Source from the content-addressed store, hash-verified

471 )
472
473 def count(
474 self,
475 sub: expr.ColumnExpression | str,
476 start: expr.ColumnExpression | int | None = None,
477 end: expr.ColumnExpression | int | None = None,
478 ) -> expr.ColumnExpression:
479 """Returns the number of non-overlapping occurrences of substring sub in the range [start, end).
480 Optional arguments start and end are interpreted as in slice notation.
481
482
483 Example:
484
485 >>> import pathway as pw
486 >>> table = pw.debug.table_from_markdown(
487 ... '''
488 ... | name
489 ... 1 | Alice
490 ... 2 | Hello
491 ... 3 | World
492 ... 4 | Zoo
493 ... '''
494 ... )
495 >>> table += table.select(count=table.name.str.count("o"))
496 >>> pw.debug.compute_and_print(table, include_id=False)
497 name | count
498 Alice | 0
499 Hello | 1
500 World | 1
501 Zoo | 2
502 """
503
504 return expr.MethodCallExpression(
505 (
506 (
507 (
508 dt.STR,
509 dt.STR,
510 dt.Optional(dt.INT),
511 dt.Optional(dt.INT),
512 ),
513 dt.INT,
514 lambda *args: api.Expression.apply(
515 str.count, *args, dtype=dt.INT.to_engine()
516 ),
517 ),
518 ),
519 "str.count",
520 self._expression,
521 sub,
522 start,
523 end,
524 )
525
526 def find(
527 self,

Callers 15

build_pipelineMethod · 0.80
clearMethod · 0.80
thisclass.pyFile · 0.80
__init__Method · 0.80
__init__Method · 0.80
__init__Method · 0.80
processing.pyFile · 0.80
_countFunction · 0.80
__init__Method · 0.80
computeMethod · 0.80
computeMethod · 0.80

Calls 2

applyMethod · 0.80
to_engineMethod · 0.45

Tested by 15

test_groupbyFunction · 0.64
test_join_reduce_1Function · 0.64
test_join_filter_reduceFunction · 0.64
test_anyFunction · 0.64
test_sql_interview_Q2Function · 0.64
test_sql_interview_Q11Function · 0.64
test_sql_interview_Q22Function · 0.64
test_sql_interview_Q28Function · 0.64
test_stream_successFunction · 0.64