MCPcopy Index your code
hub / github.com/pathwaycom/pathway / flatten

Method flatten

python/pathway/internals/table.py:2341–2377  ·  view source on GitHub ↗

Performs a flatmap operation on a column or expression given as a first argument. Datatype of this column or expression has to be iterable or Json array. Other columns of the table are duplicated as many times as the length of the iterable. It is possible to get ids of sourc

(
        self,
        to_flatten: expr.ColumnReference,
        *,
        origin_id: str | None = None,
    )

Source from the content-addressed store, hash-verified

2339 @desugar
2340 @check_arg_types
2341 def flatten(
2342 self,
2343 to_flatten: expr.ColumnReference,
2344 *,
2345 origin_id: str | None = None,
2346 ) -> Table:
2347 """Performs a flatmap operation on a column or expression given as a first
2348 argument. Datatype of this column or expression has to be iterable or Json array.
2349 Other columns of the table are duplicated as many times as the length of the iterable.
2350
2351 It is possible to get ids of source rows by passing `origin_id` argument, which is
2352 a new name of the column with the source ids.
2353
2354 Example:
2355
2356 >>> import pathway as pw
2357 >>> t1 = pw.debug.table_from_markdown('''
2358 ... | pet | age
2359 ... 1 | Dog | 2
2360 ... 7 | Cat | 5
2361 ... ''')
2362 >>> t2 = t1.flatten(t1.pet)
2363 >>> pw.debug.compute_and_print(t2, include_id=False)
2364 pet | age
2365 C | 5
2366 D | 2
2367 a | 5
2368 g | 2
2369 o | 2
2370 t | 5
2371 """
2372 if origin_id is None:
2373 intermediate_table = self
2374 else:
2375 intermediate_table = self.with_columns(**{origin_id: thisclass.this.id})
2376
2377 return intermediate_table._flatten(to_flatten.name)
2378
2379 @contextualized_operator
2380 def _flatten(

Callers 15

apply_processorMethod · 0.80
_apply_rerankingMethod · 0.80
_pandas_transformerFunction · 0.80
multiapply_all_rowsFunction · 0.80
_repack_resultsMethod · 0.80
get_nearest_itemsMethod · 0.80
smart_fuzzy_matchFunction · 0.80
lsh_perform_queryFunction · 0.80
knn_lsh_classifyFunction · 0.80

Calls 2

with_columnsMethod · 0.95
_flattenMethod · 0.80

Tested by 15

test_flatten_simpleFunction · 0.64
test_flatten_no_originFunction · 0.64
test_flatten_empty_listsFunction · 0.64
test_sqlite_all_typesFunction · 0.64
test_json_flattenFunction · 0.64
test_flattenFunction · 0.64