Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of an aliased expression in polars?

Suppose I have a polars expression in python. Is there a straightforward way to get information about it? For example, if an expression is an alias, how might I get the name?

import polars as pl

pl.col("mpg").alias("mpg2")

I've looked through the different methods both on polars Expr and PyExpr classes, but had trouble finding anything that returned information about an expression.

like image 663
machow Avatar asked Nov 01 '25 16:11

machow


1 Answers

Polars expression have a meta namespace that allows you to get meta information about expressions.

>>> pl.col("mpg").alias("mpg2").meta.output_name()
'mpg2'
like image 79
ritchie46 Avatar answered Nov 03 '25 20:11

ritchie46