Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert between a Table and a dict[str, list[Any]] #197

Closed
lars-reimann opened this issue Apr 17, 2023 · 1 comment · Fixed by #198
Closed

Convert between a Table and a dict[str, list[Any]] #197

lars-reimann opened this issue Apr 17, 2023 · 1 comment · Fixed by #198
Assignees
Labels
enhancement 💡 New feature or request released Included in a release

Comments

@lars-reimann
Copy link
Member

lars-reimann commented Apr 17, 2023

Is your feature request related to a problem?

The easiest way to create a Table by hand (e.g. for tests) right now is to use the from_columns methods:

Table.from_columns(
    [
        Column("a", [1,2]),
        Column("b", [3,4]),
    ]
)

This is still quite verbose.

Desired solution

  • Add a new method Table.from_dict that can construct a Table like this:
Table.from_dict(
    {
        "a": [1,2],
        "b": [3,4],
    }
)

The passed dict maps column names to values.

  • Add a new method Table.to_dict that returns a dict mapping columns names to values.

Possible alternatives (optional)

No response

Screenshots (optional)

No response

Additional Context (optional)

No response

@lars-reimann lars-reimann added the enhancement 💡 New feature or request label Apr 17, 2023
@lars-reimann lars-reimann changed the title Construct a Table from a dict / create a dict from a Table Convert between a Table and a dict Apr 17, 2023
@lars-reimann lars-reimann changed the title Convert between a Table and a dict Convert between a Table and a dict[str, Any] Apr 17, 2023
@lars-reimann lars-reimann self-assigned this Apr 17, 2023
@lars-reimann lars-reimann changed the title Convert between a Table and a dict[str, Any] Convert between a Table and a dict[str, list[Any]] Apr 17, 2023
@lars-reimann lars-reimann linked a pull request Apr 17, 2023 that will close this issue
lars-reimann added a commit that referenced this issue Apr 17, 2023
Closes #197.

### Summary of Changes

Added two new methods to `Table`:
* `from_dict` can create a `Table` from a `dict`
* `to_dict` can convert a `Table` to a `dict`

---------

Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com>
lars-reimann pushed a commit that referenced this issue Apr 21, 2023
## [0.11.0](v0.10.0...v0.11.0) (2023-04-21)

### Features

* `OneHotEncoder.inverse_transform` now maintains the column order from the original table ([#195](#195)) ([3ec0041](3ec0041)), closes [#109](#109) [#109](#109)
* add `plot_` prefix back to plotting methods ([#212](#212)) ([e50c3b0](e50c3b0)), closes [#211](#211)
* adjust `Column`, `Schema` and `Table` to changes in `Row` ([#216](#216)) ([ca3eebb](ca3eebb))
* back `Row` by a `polars.DataFrame` ([#214](#214)) ([62ca34d](62ca34d)), closes [#196](#196) [#149](#149)
* clean up `Row` class ([#215](#215)) ([b12fc68](b12fc68))
* convert between `Row` and `dict` ([#206](#206)) ([e98b653](e98b653)), closes [#204](#204)
* convert between a `dict` and a `Table` ([#198](#198)) ([2a5089e](2a5089e)), closes [#197](#197)
* create column types for `polars` data types ([#208](#208)) ([e18b362](e18b362)), closes [#196](#196)
* dataframe interchange protocol ([#200](#200)) ([bea976a](bea976a)), closes [#199](#199)
* move existing ML solutions into `safeds.ml.classical` package ([#213](#213)) ([655f07f](655f07f)), closes [#210](#210)

### Bug Fixes

* `table.keep_only_columns` now maps column names to correct data ([#194](#194)) ([459ab75](459ab75)), closes [#115](#115)
* typo in type hint ([#184](#184)) ([e79727d](e79727d)), closes [#180](#180)
@lars-reimann
Copy link
Member Author

🎉 This issue has been resolved in version 0.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lars-reimann lars-reimann added the released Included in a release label Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 💡 New feature or request released Included in a release
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant