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.
Polars expression have a meta namespace that allows you to get meta information about expressions.
>>> pl.col("mpg").alias("mpg2").meta.output_name()
'mpg2'
Related
The difference seems to very different between the two compared to other languages like C or C++. Things that could be statements in C seem to be expressions in Scala. How should I differentiate them, and any reason why it’s like that?
According to Scala Language Specification, it does have statements:
Statements occur as parts of blocks and templates. A statement can be an import, a definition or an expression, or it can be empty. Statements used in the template of a class definition can also be declarations.
C++ also has expression statements and declaration statements; the main difference is that it also has additional types of statements, and their equivalents are generally expressions in Scala, so they can be used either as expression statements or as part of larger expressions.
Apologies if this has already been answered, but I'm having a surprisingly hard time using the "py" string macro included with the PyCall library when I feed it a variable representing a string instead of a simple string.
Examples:
#py_str "2 + 2"
returns 4
z = "2 + 2"
#py_str z
causes a error that interpolate_pycode does not take an Expr argument, as does #py_str ($(z)).
How can I pass #py_str a string variable?
(Just to clarify - above was a toy example, I'm using it for an application where it really is necessary).
#py_str "\$\$z" is your friend (looked at macro help using ?#py_str in REPL). Better to write the same macro as py"$$z"
From the REPL help (bolded relevant part):
py".....python code....."
Evaluate the given Python code string in the main Python module.
If the string is a single line (no newlines), then the Python
expression is evaluated and the result is returned. If the string is
multiple lines (contains a newline), then the Python code is compiled
and evaluated in the main Python module and nothing is returned.
If the o option is appended to the string, as in py"..."o, then the
return value is an unconverted PyObject; otherwise, it is
automatically converted to a native Julia type if possible.
Any $var or $(expr) expressions that appear in the Python code
(except in comments or string literals) are evaluated in Julia and
passed to Python via auto-generated global variables. This allows
you to "interpolate" Julia values into Python code.
Similarly, ny $$var or $$(expr) expressions in the Python code are
evaluated in Julia, converted to strings via string, and are pasted
into the Python code. This allows you to evaluate code where the code
itself is generated by a Julia expression.
PS the little typo ny instead of any is in the package source.
I understand Excel has a TEXTJOINfunction which allows one to display multiple values as a tuple.
I also understand Libre Office does - for whatever reason - not have them.
How do I write an auxiliary macro vec that produces the desired tuple representation for me?
E.g. =vec(A1) should produce ="("&A1&")",
=vec(A1:A3) should produce ="("&A1&","&A2&","&A3&")",
=vec(A1,X5:X99,Z3) should result in ="("&A1&","&"X5"&","&X6&...&x99&","&Z3&")"
etc, etc.
Easy enough a macro to implement in, say, bash, but I would like to just define it once then use it in calc, not constantly copy from console to spreadsheet.
How do I implement this in calc?
According to https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=67880, it is possible for a Basic function to use a variable number of arguments if it is declared with Option Compatible. This makes it behave more like MS Excel. The argument is declared as ParamArray pa().
The link that #tohuwawohu posted shows most of the implementation details needed.
To do it in a way that is more native to LibreOffice, write a Spreadsheet Add-In with a Java declaration that uses any[] as an argument. For information about add-in argument types, see https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/AddIn.html.
The actual function can also be implemented in Java. Or, it can probably be implemented in another language that accepts a variable number of arguments, such as Python *args.
According to http://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL
queries can use regular expressions on both the values and the keys. While I have no trouble using regex on the values, I'm having a problem with the keys.
The example on the wiki referenced above says (among other examples):
/* finds addr:* tags with value exactly "Foo" */
node[~"^addr:.*$"~"^Foo$"];
So, that's an example of using regex on the keys and the values.
What I am interested in is the name key. Specifically the name:en key. There are a couple problems with searching by name. Not all names are in English, and for those nodes/way/relations whose names are not in English, there is no guarantee there will be a name:en tag with an English version of the name.
In general, there is no way to know in advance if the name will be in English or that there is a name:en tag. If you only ask for name or name:en, you run the risk of finding no hit. (Of course, searching for both is no guarantee of success, either.)
I have a case where I know name fails, but name:en succeeds. That is my test case. I can query the overpass-api.de/api/interpreter using this:
[out:json][timeout:25][bbox:33.465530,36.156006,33.608615,36.574516];
(
node[name~"duma",i][place];
way[name~"duma",i][place];
>;
relation[name~"duma",i][place];
node["name:en"~"duma",i][place];
way["name:en"~"duma",i][place];
>;relation["name:en"~"duma",i][place];
);
out center;
see it on overpass
and it works fine ("duma" is not found through name, but it is found with name:en), but I find it lengthy and somewhat repetitive.
I would like to use a regular expression involving the name and name:en tags, but either the server does not understand the query or I simply am using an incorrect regex.
Using the example shown in the wiki: node[~"^addr:.*$"~"^Foo$"]
I have tried:
[~"name|name:en"~"duma",i]
[~"name.*"~"duma",i]
[~"^name.*$"~"duma",i]
and several others. I even mimicked the example with [~"^name:.*"~"duma",i] just to see if anything would be returned.
Does overpass-api.de recognize regular expressions on the keys or do I just have the regex wrong? I don't get an error from overpass-api.de, just the coordinates of the bbox and an empty result. It's usually very strict about reacting to a poortly formatted query. Thanks in advance.
That's really a bug in the Overpass API implementation concerning case-insensitive key regex matching, see this Github ticket for details.
For the time being, you can already test the patch on the development box:
http://overpass-turbo.eu/s/b1l
BTW: If you don't need case-insensitive regexp matching, this should already work on overpass-api.de as of today.
What functions do I need to call to use Regular Expressions in Systemverilog/UVM?
Note: I'm not asking how to use regular expressions, just method names.
First, if you want to use regular expression, you'll need to make sure you're using a UVM library compiled together with its DPI code (i.e. the UVM_NO_DPI define isn't set).
The methods you want to use are located in dpi/uvm_regex.svh. The main function is uvm_re_match(...), which takes as an argument a regular expression and the string to match against. This is basically a wrapper around the regexec(...) C function found in the regex.h library. It will return 0 on a match.
Another function you might want to use is uvm_glob_to_re(...) which can convert from a glob expression (the kind you get in a Linux shell) to a true regular expression.