Coder Social home page Coder Social logo

ocramz / heidi Goto Github PK

View Code? Open in Web Editor NEW
27.0 5.0 3.0 355 KB

heidi : tidy data in Haskell

License: Other

Haskell 100.00%
data-mining data-science dataframes dataframe-library dataframe data-analysis tidy-data generic-programming generics algebraic-data-types

heidi's Issues

date/ time types

Multi-key-column joins

It seems essential to me that the library be able to join using multiple columns as the join key. I don't know if the underlying Trie makes that simpler.

The simplest version might simply add a column holding a product (maybe [v]?) of the key-columns to each Frame, then join the new Frames on that new column, then remove that column in the result. That's how I'd do it from outside the library. And that doesn't seem horribly inefficient. But I'm imagining there's a better way?

FUNDING.yml parsing errors

I clicked the sponsor button for this repo and got the warning:

Some errors were encountered when parsing the FUNDING.yml file:

Some users provided are not enrolled in GitHub Sponsors. Apply to Sponsors.
Learn more about formatting FUNDING.yml.

Fix usage of Semigroup/Monoid instance of Header

Frames are not supposed to be constructed directly by the user (they should only be 'encode'd from data).
Currently we say 'hdr = mempty' in a few places for convenience (grep for all FIXMEs) but these should become a function of either inputs

For example, the header of a join of two Frames is the outer product of headers (?) -- look up schema computation in relational algebra/SQL

Blocks #11

add dplyr operations

  • mutate() adds new variables that are functions of existing variables
  • select() picks variables based on their names.
    • see the text, int etc. lenses
  • filter() picks cases based on their values.
  • summarise() reduces multiple values down to a single summary.
    - [ ] arrange() changes the ordering of the rows. not needed

Traversal' rather than Decode

We use microlens now for a more principled approach to getting/setting entries from datagrame rows.

  • filterDecode should be ported to use a Traversal' rather than Decode

tidy data operations with lists as keys

There are two internal details of the library that must be reconciled and the UX must be figured out. How to manipulate list-valued indexing keys, with little boilerplate?

  • On one hand, the generic encoding produces Row values which are keyed by lists (since the original values are flattened into a single trie, collecting record names depth-first)

encode :: (Foldable t, Heidi a) => t a -> Frame (Row [TC] VP)

  • On the other, the relational operations are completely polymorphic in the key type (as long as it's TrieKey from generic-trie, i.e. either a primitive type or a list of such etc.)

https://hackage.haskell.org/package/heidi-0.0.0/docs/Heidi-Data-Frame-Algorithms-GenericTrie.html

innerJoin :: (Foldable t, Ord v, TrieKey k, Eq v, Eq k) => k  -> k  -> t (Row k v)  -> t (Row k v)  -> Frame (Row k v)

explain/log outcome of each operation

e.g. as in https://elbersb.com/public/posts/tidylog100/

filtered <- filter(mtcars, cyl == 4)
#> filter: removed 21 rows (66%), 11 rows remaining

joined <- left_join(nycflights13::flights, nycflights13::weather,
    by = c("year", "month", "day", "origin", "hour", "time_hour"))
#> left_join: added 9 columns (temp, dewp, humid, wind_dir, wind_speed, …)
#>            > rows only in x     1,556
#>            > rows only in y  (  6,737)
#>            > matched rows     335,220
#>            >                 =========
#>            > rows total       336,776

CSV output

the Row type has a natural interpretation in cassava as well

  • import cassava
  • add necessary instances to Row

Categorical variables

various functions for manipulating cat variables, we could copy the API : https://forcats.tidyverse.org/

  • fct_reorder(): Reordering a factor by another variable.
  • fct_infreq(): Reordering a factor by the frequency of values.
  • fct_relevel(): Changing the order of a factor by hand.
  • fct_lump(): Collapsing the least/most frequent values of a factor into “other”.

Couple Frame and Header

  • A Header is uniquely determined by the type of the input data
  • once data are encoded in a Frame, we compute a Header from the type (with header)
  • relational operations such as JOINs, and tidying operations produce dataframes that have a different (larger or smaller) column set than the one of either operands
  • this is why a new Header should be derived when producing the operation result, and stored in the resulting Frame

possible representation :

data Frame = Frame {
    frameRows :: [Row [TC] VP]
  , frameHeader :: Header [TC]
}

currently, the information in Header and Val is not compatible:

λ> gflattenHM $ MkC1 42
fromList [([TC "C" "c1"],42)]
λ> 
λ> header (Proxy @C)
HSum "C" (fromList [("MkC3",HLeaf "()"),("MkC1",HLeaf "Int"),("MkC2",HProd "A" (fromList [("MkA",HLeaf "Int")]))])

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.