GithubHelp home page GithubHelp logo

Comments (7)

philss avatar philss commented on August 16, 2024 1

Hi @hoetmaaiers πŸ‘‹

I believe you can't change the type of the series in the transformation.
Since you are trying to execute Elixir code for this, how about using Enum.map/2 for the transformation?

Something like this:

alias Explorer.{DataFrame, Series}

df = DataFrame.from_map(%{a: ["00:30:00", "01:00:00", "05:30:00"]})

transform_duration = fn duration ->
  time = Time.from_iso8601!(duration)
  time.hour + (time.minute / 60) + (time.second / 60*60)
end

new_a_series = df["a"] |> Series.to_list() |> Enum.map(transform_duration) |> Series.from_list()

DataFrame.mutate(df, a: new_a_series)

WDYT?

PS: you don't need that |> Series.from_list() part for this to work.

from explorer.

cigrainger avatar cigrainger commented on August 16, 2024 1

This is a bug! We shouldn't assume you're not changing dtypes when using Series.transform/2. I'll fix it. πŸ‘

from explorer.

cigrainger avatar cigrainger commented on August 16, 2024 1

@hoetmaaiers the solution suggested by @philss is basically what Explorer is doing under the hood anyway. The fix I pushed today means your original code will work now -- it was a bug I introduced when implementing Series.transform/2. I accidentally had it so there was an assumption that transform would retain the original dtype and that's not every useful πŸ˜€. So now we check the dtype of the new list before creating a series from it.

from explorer.

hoetmaaiers avatar hoetmaaiers commented on August 16, 2024

Thank you @philss , thinking outside Explorer with regular Elixir, why didn't I think of this myself...

@cigrainger, does this mean @philss isn't the only way of doing this?

from explorer.

hoetmaaiers avatar hoetmaaiers commented on August 16, 2024

The combination of DataFrame.mutate and Series.transform isn't working for me. Probably it is my bad, but the documentation seems to miss this combination. What am I doing wrong?

df = DataFrame.from_map(%{a: ["00:30:00", "01:00:00", "05:30:00"]})

transform_duration = fn duration ->
  time = Time.from_iso8601!(duration)
  time.hour + (time.minute / 60) + (time.second / 60*60)
end

DataFrame.mutate(df, a: &Series.transform(&transform_duration.(&1["a"])))

Returns me this compile error: ** (CompileError) dataframe.exs:36: nested captures via & are not allowed: &transform_duration.(&1["a"])

from explorer.

josevalim avatar josevalim commented on August 16, 2024

You are not allowed to use & inside &, that’s what the compile error is telling you. Could the error message have been clearer in this case?

from explorer.

hoetmaaiers avatar hoetmaaiers commented on August 16, 2024

No the error message is clear, no doubt. I'm struggling with the proper combination of transform and mutate and tried several approaches.

Maybe the documentation for this use case can be clearer? I based myself on the notebook example in this repo.

from explorer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.