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

feat: allow dicts in ibis.literal for structs #3118

Closed
cpcloud opened this issue Nov 9, 2021 · 7 comments · Fixed by #3367
Closed

feat: allow dicts in ibis.literal for structs #3118

cpcloud opened this issue Nov 9, 2021 · 7 comments · Fixed by #3367
Labels
expressions Issues or PRs related to the expression API feature Features or general enhancements onboarding Issues that can be addressed by someone less familiar with ibis
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented Nov 9, 2021

Currently a struct must be an OrderedDict, but since 3.6 there's no reason we can't allow at least dicts any possibly any mapping:

>>> import ibis
>>> ibis.literal({"a": "b", "c": "d"}, type="struct<a: string, c: string>")
TypeError: Value {'a': 'b', 'c': 'd'} cannot be safely coerced to struct<a: string, c: string>
@cpcloud cpcloud added feature Features or general enhancements expressions Issues or PRs related to the expression API labels Nov 9, 2021
@cpcloud cpcloud added the onboarding Issues that can be addressed by someone less familiar with ibis label Nov 22, 2021
@cpcloud cpcloud changed the title feat: allow at least dicts in ibis.literal feat: allow at least dicts in ibis.literal for maps Dec 10, 2021
@cpcloud cpcloud changed the title feat: allow at least dicts in ibis.literal for maps feat: allow at least dicts in ibis.literal for struct Dec 17, 2021
@cpcloud cpcloud changed the title feat: allow at least dicts in ibis.literal for struct feat: allow at least dicts in ibis.literal for structs Dec 17, 2021
@jjram20
Copy link

jjram20 commented Jan 5, 2022

I would like to take this issue. /take

@cpcloud
Copy link
Member Author

cpcloud commented Jan 6, 2022

@jjram20 Cool, just write only /take!

@jjram20
Copy link

jjram20 commented Jan 6, 2022

/take

@jjram20
Copy link

jjram20 commented Jan 6, 2022

Hi, did it work now?

@jjram20
Copy link

jjram20 commented Jan 6, 2022

/take

@cpcloud
Copy link
Member Author

cpcloud commented Jan 6, 2022

The action might be backed up in the CI queue, give it a few minutes.

@cpcloud cpcloud assigned cpcloud and jjram20 and unassigned cpcloud Jan 6, 2022
@cpcloud cpcloud added this to the 3.0.0 milestone Jan 25, 2022
@cpcloud cpcloud changed the title feat: allow at least dicts in ibis.literal for structs feat: allow dicts in ibis.literal for structs Jan 26, 2022
saulpw added a commit to saulpw/ibis that referenced this issue Jan 28, 2022
Prefer these instead of the more generic ibis.literal to create compound literals.
Like .array() for array types.

closes ibis-project#3118
@saulpw
Copy link
Contributor

saulpw commented Jan 28, 2022

We're going to keep ibis.literal() as it is for constructing plain literal expressions (int, float, string, etc), and add new constructors for compound literal expressions, just like the existing ibis.array():

  • ibis.struct()
  • ibis.map()

These new constructors take a Python dict as the value, and an optional type kwarg like ibis.literal() (this type kwarg is also added to ibis.array() for symmetry). struct() creates a literal value expression in which the field names and value types are fixed, and the value types can be heterogenous within the same struct. map() creates a literal value expression in which the types of the keys and values are fixed and homogenous, but which can have any set of key/value pairs (and any number of them).

literal() will still continue to work as it has (e.g. it needs an OrderedDict specifically to construct a StructValue), but these special constructors should be preferred for non-plain literals in new code.

saulpw added a commit to saulpw/ibis that referenced this issue Jan 31, 2022
Prefer these instead of the more generic ibis.literal to create compound literals.
Like .array() for array types.

closes ibis-project#3118
cpcloud pushed a commit that referenced this issue Feb 1, 2022
Prefer these instead of the more generic ibis.literal to create compound literals.
Like .array() for array types.

closes #3118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expressions Issues or PRs related to the expression API feature Features or general enhancements onboarding Issues that can be addressed by someone less familiar with ibis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants