sehHeiden

sehHeiden

Compared to Pythons pandas I am missing some functions for DataFrames and Series from Explorer, or I have to apply a workaround, which makes everything less expressive.

DataFrames have a drop_nil function. Why don’t have Series have it? Well, I can convert it to list, drop them from the list and then convert back…

By the documentation the series have a contains function, that use a regex, could not get with working with a compiled regex string. I did a mapping instead:

filter = df["content"]
|> S.to_list()
|> Enum.map(&Regex.match?(tags,&1))
|> S.from_list()

This returns a series of boolean. But I can not use it filter a DataFrame or a Series? At least I did not find it in the reference and also no way around. It neighter a filter, filter_with nor a slice. Slice needs indices. How do I get the indices, where the value is :true?

The last question is, about Date(time) columns. How can I convert a Date to a calendar week?

Update:

post_filter = df["content"]
|> S.downcase()
|> S.to_list()
|> Enum.map(&Regex.match?(tags,&1))
|> Enum.with_index()
|> Enum.filter(&(elem(&1, 0) == true))
|> Enum.map(&(elem(&1, 1)))

Can be used as input for the slicing…

Showing Posts 1 to 10

billylanchantin

billylanchantin

I believe you want Explorer.Series.mask/2.

content = S.from_list(["aa", "ab", "bc"])
# #Explorer.Series<
#   Polars[3]
#   string ["aa", "ab", "bc"]
# >
mask = S.transform(content, &Regex.match?(~r/a.+/, &1))
# #Explorer.Series<
#   Polars[3]
#   boolean [true, true, false]
# >
S.mask(content, mask)
# #Explorer.Series<
#   Polars[2]
#   string ["aa", "ab"]
# >
billylanchantin

billylanchantin

Sorry I missed this part. Also I’m not sure what a “calendar week” is. Is that the index of the week in the calendar year? If so this could work:

S.from_list([~D[2023-01-01], ~D[2023-01-08], ~D[2023-02-23]])
# #Explorer.Series<
#   Polars[3]
#   date [2023-01-01, 2023-01-08, 2023-02-23]
# >
|> S.transform(&Date.day_of_year/1)
# #Explorer.Series<
#   Polars[3]
#   integer [1, 8, 54]
# >
|> S.quotient(7)
# #Explorer.Series<
#   Polars[3]
#   integer [0, 1, 7]
# >
josevalim

josevalim

Creator of Elixir

We will also gladly accept PRs that add missing functions. We know that we are missing many of them. :slight_smile:

sehHeiden

sehHeiden OP

Thanks. @billylanchantin the mask function helped alot. Sorry, that I was not able find it.

The calendar week is somewhat more complex, because it first week of the year, might partly be counted as the last week of the year before. I had to look it up. Normally I would expect it to be a part of the date(time) library

wikipedia states the ISO week date computes as:

Algorithm

  1. Subtract the weekday number from the ordinal day of the year.
  2. Add 10.
  3. Divide by 7, discard the remainder.
  • If the week number thus obtained equals 0, it means that the given date belongs to the preceding (week-based) year.
  • If a week number of 53 is obtained, one must check that the date is not actually in week 1 of the following year.

The edge cases below, Is what I meant and makes me wonder, whether I really understand these.

billylanchantin

billylanchantin

You’re welcome. And no worries! There are a lot of functions to sift through.

Ah gotcha. Yeah that looks tricky to implement yourself.

As @josevalim said, there are missing functions. If you look at the Elixir side of things:

They do not have a function that corresponds to what you want. But you’re in luck because Polars does!

Unless I’m missing something, it should be straightforward to add that function to Explorer if you wanted to do a PR :slight_smile:

josevalim

josevalim

Creator of Elixir

And if you can’t submit a PR, open up an issue and we will look into it :slight_smile:

sehHeiden

sehHeiden OP

Sorry for answering late. The messages from the elixir-forum always end up in my spam filter. About the PR… a) a I very new to Elixir not so bold to mess up some core libraries :wink: . Also barely have to time.

But creating an issue is doable. :wink:

billylanchantin

billylanchantin

Hi @sehHeiden,

The function is now on main (José reviews PRs quick!):

Add `day_of_year` and `week_of_year` by billylanchantin · Pull Request #717 · elixir-explorer/explorer · GitHub

So if you get the latest ref, you can now do:

[~D[2023-01-01], ~D[2023-01-08], ~D[2023-02-23]]
|> S.from_list()
|> S.week_of_year()
# #Explorer.Series<
#   Polars[3]
#   integer [52, 1, 8]
# >

Since you’re new to Elixir, you can get the latest ref by adding the following to your project’s mix.exs:

  # list of deps
  [
    # ...
    {:explorer,
     git: "https://github.com/elixir-explorer/explorer.git",
     # This is the current ref of main.
     # It may change, but as long as the ref is after this one,
     # you'll have access to the function.
     ref: "aef274989ab490b0a392ccd19ec24b286a8cda1c",
     override: true},
    # ...
  ]

There are other ways of doing this too, but that should get you started.

sehHeiden

sehHeiden OP

Thanks for your message @billylanchantin . I did have a look at the commits. Have been many changes for appyling a single function.

sehHeiden

sehHeiden OP

Hi @billylanchantin I tried, to do so: I get a error message from rustler:

==> explorer
Compiling 24 files (.ex)

== Compilation error in file lib/explorer/polars_backend/native.ex ==
** (ErlangError) Erlang error: :enoent
    (elixir 1.14.5) lib/system.ex:1060: System.cmd("cargo", ["metadata", "--format-version=1"], [cd: "native/explorer"])
    (rustler 0.29.1) lib/rustler/compiler/config.ex:83: Rustler.Compiler.Config.metadata!/1
    (rustler 0.29.1) lib/rustler/compiler/config.ex:70: Rustler.Compiler.Config.build/1
    (rustler 0.29.1) lib/rustler/compiler.ex:9: Rustler.Compiler.compile_crate/2
    lib/explorer/polars_backend/native.ex:11: (module)

I have no problem with building the hex version

Where Next? Top

Trending in Questions Top

water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews