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

Weekly Status Log: Python API #2

Open
domoritz opened this issue Sep 16, 2024 · 10 comments
Open

Weekly Status Log: Python API #2

domoritz opened this issue Sep 16, 2024 · 10 comments
Assignees

Comments

@domoritz
Copy link
Member

domoritz commented Sep 16, 2024

This is for uwdata#395. Code changes in #10.

@Hamzu24 Hamzu24 self-assigned this Sep 26, 2024
@Xinyue-Yang Xinyue-Yang self-assigned this Oct 2, 2024
@mhli1260
Copy link

mhli1260 commented Oct 2, 2024

Oct 2:

  • created a simple version of the schema in testingSchema.json to test out the generation of classes
  • when running "python generated_wrapper_schema.py", outputs classes into generated_classes.py
  • working on creating a test.py to test calls on these classes
  • tested running on the actual mosaic schema (v0.10.0), and seemed to be generating classes upon first glance (but will need to look more in depth at the classes that are being generated to see if classes are missing/incorrect that should exist/need to be corrected based on schema?)

Issues:

  • $ref outputs the classes beneath the classes that reference them in generated_classes.py -> leads to many classes not defined errors

@harrylojames
Copy link

Just to say really excited about this and thank you for providing a weekly status log!

@mhli1260 mhli1260 self-assigned this Oct 2, 2024
@Hamzu24
Copy link

Hamzu24 commented Oct 2, 2024

I built upon this to:

  • Load the python classes in topological order of references
  • Fixed the download schema so it works fully

The Altair schema sorted the references by topological order, so I assumed we had to do the same. However, I realized that some of the references are cyclical? I would like to ask about this in the meeting.

@Xinyue-Yang
Copy link

My last week's progress:

  • created utils.py, which includes utilities for working with schemas
  • Implemented jsonschema_to_python_types to do type conversion between JSON and python types
  • Implemented get_type_hint to determine the appropriate type hint based on the property schema
  • Generate__init__method parameters

@Hamzu24
Copy link

Hamzu24 commented Oct 23, 2024

This week's progress for the team:

  • Added lots of test cases
  • Fixed typing and reference errors
  • Extended the typing in the schema generator
  • Made the schema generator into a package

@mhli1260
Copy link

mhli1260 commented Nov 6, 2024

11/6 Updates:

  • virtual environment
  • created a to_dict function that would correctly create a spec using calls to our generated python classes
  • got an example running using Mosaic widget after generating spec

@domoritz
Copy link
Member Author

domoritz commented Nov 6, 2024

Eventually, we want to use a submodule to import schemaapi as in gosling-lang/gos#101.

@Hamzu24
Copy link

Hamzu24 commented Nov 12, 2024

11/12 Updates:

  • I tried using altair's to_dict function instead of our own one. This proved to be difficult because of their exclusive use of SchemaBase objects to encapsulate data in a specification. I'm not completely sure how or if it is even possible to convert an object, such as the one we made using our schema wrapper's classes, to a SchemaBase object. To further look into this, could you direct me to the start of the existing mosaic pipeline (that uses altair's functions) for generating schemas from yaml or JS?
  • updated tests using assert statements to check for generation of correct specs

@Hamzu24
Copy link

Hamzu24 commented Nov 12, 2024

Disregard this- got it working using altair's _todict function

@domoritz
Copy link
Member Author

modify https://github.com/cmudig/mosaic/blob/main/bin/prepare-examples.js to use new astToPython (you need to write).

roughly what the generated python should look like

# line.py

from mosaic import Plot, PlotMark, LineY, PlotFrom, ChannelValueSpec, ChannelValue

plot = Plot(
    plot = [PlotMark(LineY(
        mark="lineY", 
        data=PlotFrom(from_="aapl"), 
        x=ChannelValueSpec(ChannelValue("Date")), 
        y=ChannelValueSpec(ChannelValue("Close"))
    ))],
    width = 680,
    height = 200
)

# in tests

assert json_spec == plot.to_dict()

mhli1260 added a commit that referenced this issue Nov 20, 2024
Creating generate_mosaic_schema_wrapper.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants