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

Provide a mechanism for generating entire tables #7

Merged
merged 3 commits into from
Feb 27, 2024
Merged

Conversation

ararslan
Copy link
Member

This adds functions collect_tables, which turns the output of generate into a NamedTuple of tables, and generate_tables which is just a convenience atop collect_tables(generate(...)).

Example using the setup in the package's README:

julia> tables = MockTableGenerators.generate_tables(StableRNG(11), DAG);

julia> tables.person
5-element Vector{NamedTuple{(:id, :first_name, :last_name), Tuple{UUID, String, String}}}:
 (id = UUID("5a3d3d5e-ff13-417a-8b79-7c9e0c9cfb56"), first_name = "David", last_name = "Brown")
 (id = UUID("3c65b575-6628-4583-824e-a5340d3a02a8"), first_name = "Carol", last_name = "Johnson")
 (id = UUID("7aef3538-782c-42b3-affb-ab188f985ce1"), first_name = "David", last_name = "Williams")
 (id = UUID("35131b5b-e0c7-4cb7-9ffc-cd5524c5617e"), first_name = "David", last_name = "Smith")
 (id = UUID("5593e69f-b17b-41f9-a773-c2889a31cf14"), first_name = "Alice", last_name = "Johnson")

julia> tables.symptom
23-element Vector{NamedTuple{(:visit_id, :symptom), Tuple{UUID, String}}}:
 (visit_id = UUID("335cae41-dd9e-47c5-8628-da0e4daf1eca"), symptom = "Chills")
 (visit_id = UUID("335cae41-dd9e-47c5-8628-da0e4daf1eca"), symptom = "Fever")
 (visit_id = UUID("e5ed237f-6991-4eaf-8ab9-89d6862db6ea"), symptom = "Runny nose")
 (visit_id = UUID("e5ed237f-6991-4eaf-8ab9-89d6862db6ea"), symptom = "Runny nose")
 (visit_id = UUID("c1fd8091-1cad-4ff5-bc0a-c0ebd335c020"), symptom = "Fever")
 (visit_id = UUID("c1fd8091-1cad-4ff5-bc0a-c0ebd335c020"), symptom = "Fever")
 (visit_id = UUID("70754117-e13f-46ed-abfd-856153c66eea"), symptom = "Chills")
 (visit_id = UUID("70754117-e13f-46ed-abfd-856153c66eea"), symptom = "Chills")
 (visit_id = UUID("d2407228-04ac-43a3-bdc3-52d2140c6753"), symptom = "Muscle Loss")
 (visit_id = UUID("d2407228-04ac-43a3-bdc3-52d2140c6753"), symptom = "Fainting")
 (visit_id = UUID("84495b2f-11ec-4b38-9438-3a2912684539"), symptom = "Chills")
 (visit_id = UUID("5ddce3a4-3e12-4a48-ae05-b34ee5f0e074"), symptom = "Fatigue")
 (visit_id = UUID("5ddce3a4-3e12-4a48-ae05-b34ee5f0e074"), symptom = "Fever")
 (visit_id = UUID("3a2a8739-e004-4e5c-9ad5-5f529f10f507"), symptom = "Muscle Loss")
 (visit_id = UUID("3a2a8739-e004-4e5c-9ad5-5f529f10f507"), symptom = "Fainting")
 (visit_id = UUID("c5cdf617-56c6-452c-83ea-ca9c1975e1ac"), symptom = "Runny nose")
 (visit_id = UUID("a7ab506b-916d-4018-978a-b397500c48a5"), symptom = "Fatigue")
 (visit_id = UUID("a7ab506b-916d-4018-978a-b397500c48a5"), symptom = "Fatigue")
 (visit_id = UUID("016f4a4c-82b2-4c08-92cf-5274ef2c824a"), symptom = "Muscle Loss")
 (visit_id = UUID("016f4a4c-82b2-4c08-92cf-5274ef2c824a"), symptom = "Fainting")
 (visit_id = UUID("63cd1893-dea6-4eb2-9eaf-a6fbaf4adb05"), symptom = "Fatigue")
 (visit_id = UUID("5d5d7351-afbc-454d-9ba8-d6d1a2e14761"), symptom = "Runny nose")
 (visit_id = UUID("5d5d7351-afbc-454d-9ba8-d6d1a2e14761"), symptom = "Fatigue")

julia> tables.visit
13-element Vector{NamedTuple{(:id, :person_id, :index, :date), Tuple{UUID, UUID, Int64, Date}}}:
 (id = UUID("335cae41-dd9e-47c5-8628-da0e4daf1eca"), person_id = UUID("5a3d3d5e-ff13-417a-8b79-7c9e0c9cfb56"), index = 1, date = Date("1991-09-12"))
 (id = UUID("e5ed237f-6991-4eaf-8ab9-89d6862db6ea"), person_id = UUID("5a3d3d5e-ff13-417a-8b79-7c9e0c9cfb56"), index = 2, date = Date("1995-11-04"))
 (id = UUID("c1fd8091-1cad-4ff5-bc0a-c0ebd335c020"), person_id = UUID("3c65b575-6628-4583-824e-a5340d3a02a8"), index = 1, date = Date("1984-05-31"))
 (id = UUID("70754117-e13f-46ed-abfd-856153c66eea"), person_id = UUID("3c65b575-6628-4583-824e-a5340d3a02a8"), index = 2, date = Date("1991-12-26"))
 (id = UUID("d2407228-04ac-43a3-bdc3-52d2140c6753"), person_id = UUID("3c65b575-6628-4583-824e-a5340d3a02a8"), index = 3, date = Date("1995-01-10"))
 (id = UUID("84495b2f-11ec-4b38-9438-3a2912684539"), person_id = UUID("7aef3538-782c-42b3-affb-ab188f985ce1"), index = 1, date = Date("1981-01-02"))
 (id = UUID("5ddce3a4-3e12-4a48-ae05-b34ee5f0e074"), person_id = UUID("7aef3538-782c-42b3-affb-ab188f985ce1"), index = 2, date = Date("1981-12-14"))
 (id = UUID("3a2a8739-e004-4e5c-9ad5-5f529f10f507"), person_id = UUID("7aef3538-782c-42b3-affb-ab188f985ce1"), index = 3, date = Date("1992-07-11"))
 (id = UUID("c5cdf617-56c6-452c-83ea-ca9c1975e1ac"), person_id = UUID("35131b5b-e0c7-4cb7-9ffc-cd5524c5617e"), index = 1, date = Date("1983-11-22"))
 (id = UUID("a7ab506b-916d-4018-978a-b397500c48a5"), person_id = UUID("35131b5b-e0c7-4cb7-9ffc-cd5524c5617e"), index = 2, date = Date("1996-03-27"))
 (id = UUID("016f4a4c-82b2-4c08-92cf-5274ef2c824a"), person_id = UUID("35131b5b-e0c7-4cb7-9ffc-cd5524c5617e"), index = 3, date = Date("1998-04-29"))
 (id = UUID("63cd1893-dea6-4eb2-9eaf-a6fbaf4adb05"), person_id = UUID("5593e69f-b17b-41f9-a773-c2889a31cf14"), index = 1, date = Date("1982-05-03"))
 (id = UUID("5d5d7351-afbc-454d-9ba8-d6d1a2e14761"), person_id = UUID("5593e69f-b17b-41f9-a773-c2889a31cf14"), index = 2, date = Date("1990-01-09"))

Closes #6

I've had this change locally for months and had just forgotten to push it. 🙃

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (75f83ed) 100.00% compared to head (27b9aff) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #7   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         3    +1     
  Lines           44        54   +10     
=========================================
+ Hits            44        54   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@glennmoy glennmoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just needs a version bump :)

@ericphanson
Copy link
Member

can we update the docs? E.g. the change in #8 should probably be replaced with this

This adds functions `collect_tables`, which turns the output of
`generate` into a `NamedTuple` of tables, and `generate_tables` which is
just a convenience atop `collect_tables(generate(...))`.
The README was updated for the change to include an `rng` argument in
method definitions but the package docs were not. This commit makes the
example runnable. It also replaces the `OrderedDict` example with
`collect_tables`.
@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (556642f) to head (85f924b).

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #7   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           45        54    +9     
=========================================
+ Hits            45        54    +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ararslan
Copy link
Member Author

ararslan commented Feb 27, 2024

Version bumped, docs updated. Looks like #3 updated the README but not the docs, so the change made to the documentation is larger than it would otherwise be.

@ararslan
Copy link
Member Author

Requesting re-review due to the docs change.

@ararslan ararslan merged commit 26cc98c into main Feb 27, 2024
3 checks passed
@ararslan ararslan deleted the aa/tables branch February 27, 2024 20:58
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

Successfully merging this pull request may close these issues.

add utility function for generating actual mock tables, not just a network of mocked records
4 participants