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

RDRP-1081- pnp 2021 backdata prep: fix the move to instance 1 #392

Merged
merged 10 commits into from
Jan 6, 2025

Conversation

AnneONS
Copy link
Collaborator

@AnneONS AnneONS commented Dec 17, 2024

Pull Request submission

This PR contains code to fix the function which moves values for the 2xx and 3xx cols from instance 0 to instance 1, and replace the values in instance 0 with zeros.

It was also necessary to ensure that an instance 1 is created if one doesn't exist yet for a reference.

A unit test has been included to check this is working as it should

Also, a new function to multiply the 2xx and 3xx cols by 1000

In addition, a very good investigation comparing the outputs to the raw data is needed.

Closes #1081

Code

  • Code runs The code runs on my machine and/or CDSW
  • Conflicts resolved There are no conflicts (I have performed a rebase if necessary)
  • Requirements My/our code functions according to the requirements of the ticket
  • Dependencies I have updated the environment yaml so it includes any new libraries I have used
  • Configuration file updated any high level parameters that the user may interact with have been put into the config file (and imported to the script)
  • Clean Code
    • Code is as PEP 8 compliant as I can humanly make it
    • Code passess flake8 linting check
    • Code adheres to DRY
  • Type hints All new functions have type hints

Documentation

Any new code includes all the following forms of documentation:

  • Function Documentation Docstrings within the function(s')/methods have been created
    • Includes Args and returns for all major functions
    • The docstring details data types
  • Updated Documentation: User and/or developer working doc has been updated

Data

  • All data needed to run this script is available in Dev/Test
  • All data is excluded from this pull request
  • Secrets checker pre-commit passes

Testing

  • Unit tests Unit tests have been created and are passing or a new ticket to create tests has been created

Peer Review Section

  • All requirements install from (updated) requirements.txt
  • Documentation has been created and is clear - check the working document
  • Doctrings (Google format) have been created and accurately describe the function's functionality
  • Unit tests pass, or if not present a new ticket to create tests has been created
  • Code runs The code runs on reviewer's machine and/or CDSW

Final approval (post-review)

The author has responded to my review and made changes to my satisfaction.

  • I recommend merging this request.

Review comments

Insert detailed comments here!

These might include, but not exclusively:

  • bugs that need fixing (does it work as expected? and does it work with other code
    that it is likely to interact with?)
  • alternative methods (could it be written more efficiently or with more clarity?)
  • documentation improvements (does the documentation reflect how the code actually works?)
  • additional tests that should be implemented (do the tests effectively assure that it
    works correctly?)
  • code style improvements (could the code be written more clearly?)
  • Do the changes represent a change in functionality so the version number should increase? Start a discussion if so.
  • As a review you can generates the same outputs from running the code

Your suggestions should be tailored to the code that you are reviewing.
Be critical and clear, but not mean. Ask questions and set actions.

@AnneONS AnneONS requested a review from Ryan2Y79 December 17, 2024 10:05
Copy link

github-actions bot commented Dec 17, 2024

Percentage Coverage for this PR

Detailed Coverage Report
FileStmtsMissCoverMissing
src
   __init__.py00100% 
src/construction
   __init__.py00100% 
   all_data_construction.py47470%1, 3–4, 6, 8, 16, 22, 45–46, 49, 54–55, 59–61, 65–66, 69, 76–78, 83, 86–90, 92, 97–98, 103–104, 107–109, 113, 117–120, 125–126, 128, 133–134, 138, 140
   construction_helpers.py1041486%31–42, 239, 306
   construction_main.py27270%2–3, 5, 7, 11–12, 15, 18, 54–57, 64, 68–71, 74, 78–81, 84, 89–91, 93
   construction_read_validate.py34340%2–3, 5, 8, 11, 16, 18, 21, 46–49, 51–52, 55–56, 59, 66–68, 72–73, 79, 82, 101–103, 105–106, 109, 116–117, 122, 129
   construction_validation.py102991%83, 86, 113, 121–122, 127, 138, 168, 218
   postcode_construction.py21210%1–2, 4–6, 9, 26, 29, 32, 37, 40–41, 44, 47–49, 51, 55, 59, 62–63
src/estimation
   __init__.py00100% 
   apply_weights.py18288%46–47
   calculate_weights.py520100% 
   estimation_main.py22220%2–4, 6–8, 10, 13, 29, 35, 38, 41–42, 44–51, 53
src/freezing
   __init__.py00100% 
   freezing_apply_changes.py702170%31–34, 37–38, 41–43, 46–49, 53, 61–64, 68–69, 71
   freezing_compare.py682267%107–108, 156–157, 181, 184, 187–189, 193–195, 197–199, 201–202, 234, 257, 260, 263, 266
   freezing_main.py46460%1–3, 5, 7–12, 15, 18, 42–43, 46–47, 49–53, 55, 63, 66–68, 71–72, 76–78, 83–84, 86–87, 90–91, 95, 98, 109–112, 114–116
   freezing_utils.py110100% 
src/imputation
   MoR.py150795%57–58, 73, 293, 445, 489–490
   __init__.py00100% 
   apportionment.py361072%124, 126, 141, 143, 145, 157–159, 162, 164
   expansion_imputation.py373018%23–24, 26–27, 30, 33–35, 39, 42, 44, 47–48, 50, 53, 56, 76–78, 82, 85, 88, 91, 97, 102, 105, 107, 113, 116, 120
   imputation_helpers.py1385659%67, 69, 78, 85, 98–101, 104–105, 107–108, 110–111, 113–114, 116–117, 119–120, 122–123, 125, 134, 136–137, 139–140, 309, 311–312, 316–317, 319, 323, 344, 347, 351, 354–355, 357, 445, 447–448, 451, 463–464, 467–468, 470, 472, 488–489, 492–493, 495
   imputation_main.py75750%3–6, 8–18, 21, 24, 55, 58, 61, 64–65, 68–69, 72, 74, 79, 82–83, 86, 89–90, 93, 95, 99–100, 104–106, 109, 113–114, 117–118, 121–124, 126, 130, 133–134, 136–140, 142, 144–146, 148–150, 152–153, 156, 159, 162–167, 169
   impute_civ_def.py994752%165, 168, 198, 200–201, 204–205, 208–210, 215–216, 218, 221, 223–226, 228, 230, 235–236, 238, 241, 243–245, 248, 250–251, 253–254, 256–257, 270, 273–277, 279–280, 283–284, 286–287, 289
   manual_imputation.py19190%1–2, 4, 6, 9–10, 28–29, 33, 35, 37, 44, 59, 61–62, 64–65, 67–68
   sf_expansion.py746117%24, 27, 30–31, 34–35, 38, 41, 44–45, 48, 50, 57–58, 61, 66–67, 70, 72, 75–76, 78, 80, 83, 87, 89, 100, 103, 107, 109–110, 112, 114, 117, 120, 129, 132, 135, 144, 147, 149, 155, 161, 173, 176, 181–182, 184, 192–193, 196, 200, 204, 207, 215, 222–223, 226, 228, 232, 234
   short_to_long.py21210%1, 3–4, 7, 20, 23, 25, 32–33, 35, 37–38, 40–41, 43–45, 47, 49, 53, 55
   tmi_imputation.py18112729%28–29, 57, 59, 65–67, 71, 77, 80, 82, 87, 92, 97, 218, 221, 223, 226, 230, 234, 256–257, 260, 263–264, 267, 270–271, 274, 276–277, 279, 281, 284–285, 287, 289, 292, 295–296, 298, 301–303, 305–308, 310, 326, 328, 335, 337–338, 340–341, 343, 345, 347, 349, 352, 355–356, 359, 361, 363, 381–382, 384, 386–387, 389–391, 393–394, 397, 399–400, 403, 405–406, 424, 426, 429–431, 433, 435–436, 438–439, 442, 444–445, 448, 450, 452–453, 473, 477, 480–481, 484–485, 488, 491, 493, 498, 500, 505, 507, 514–515, 520, 527–528, 530, 533–534, 536, 539, 541, 543, 548, 550–551
src/mapping
   __init__.py00100% 
   cellno_mapping.py17476%49–51, 53
   itl_mapping.py100100% 
   mapping_helpers.py55590%24–27, 69
   mapping_main.py49490%3–5, 7–15, 17, 20, 45, 50, 59, 68, 75, 78, 85, 88–90, 97, 99, 102–104, 107, 109–111, 114, 117, 122–123, 126, 128–132, 134–136, 139, 142, 145
   pg_conversion.py40880%52, 55, 58, 122, 125, 128, 162–163
   pnp_mapping.py24240%1–2, 5, 8, 17–19, 21, 24, 27, 38–40, 42, 46, 49, 57, 73, 75, 78, 89–91, 93
   ultfoc_mapping.py34488%49–51, 95
src/northern_ireland
   __init__.py00100% 
   ni_headcount_fte.py29290%2–4, 6, 8, 11, 25, 27, 29, 31, 33, 35, 37, 40, 55, 57–59, 61, 63–64, 66–67, 69, 72, 81, 83–84, 86
   ni_main.py21210%3–9, 11, 14, 34, 37–39, 45, 52–54, 62, 64–65, 67
   ni_staging.py33330%3–6, 8–9, 11, 14, 22, 25, 27–29, 31, 34, 40, 44, 46, 49, 78–79, 82, 87, 91, 94, 97–102, 104, 106
src/outlier_detection
   __init__.py00100% 
   auto_outliers.py810100% 
   manual_outliers.py160100% 
   outlier_main.py39390%2–4, 6–8, 10, 13, 42, 44–46, 48–49, 52, 55, 58–63, 65, 70–71, 74, 79–82, 85–89, 91, 94, 96, 98
src/outputs
   __init__.py00100% 
   export_files.py92920%5–11, 13–14, 18, 24, 42, 44, 51–54, 61, 68, 73, 76, 103, 109, 112, 119, 121, 124, 130, 132–133, 136–140, 143–144, 147, 158–160, 162, 165, 178, 180–181, 183, 186, 206, 209, 212–213, 220, 224, 227–229, 232, 234, 236, 238–239, 241, 244–248, 250–251, 253, 256–258, 261, 264, 267, 282, 285–286, 294, 297, 299, 301, 311, 313–315, 324, 326, 329–330
   form_output_prep.py181327%25–27, 29–30, 34, 36–37, 39, 41, 43, 47, 49
   frozen_group.py43430%3–4, 6, 8–11, 13, 16, 45, 47–50, 53, 71, 123, 134, 161, 164–168, 170, 172, 175, 178–179, 181, 184, 187, 192–193, 196–197, 200, 203–205, 208–209, 211
   gb_sas.py23230%2–4, 6–9, 11, 14, 30, 33, 38, 41, 44, 47, 52, 55, 58–60, 63–64, 66
   intram_by_civil_defence.py210100% 
   intram_by_itl.py541572%44–47, 51, 141, 144, 147–149, 152–153, 157–158, 167
   intram_by_pg.py350100% 
   intram_by_sic.py33330%2–5, 7, 10, 30–31, 34–35, 38–39, 41, 44–46, 51, 67–71, 73, 76, 79, 82, 85, 88–89, 92–93, 96, 98
   intram_totals.py14140%3–4, 6–7, 9, 12, 29–30, 33, 36, 39–40, 42–43
   long_form.py17170%2–4, 6–9, 11, 14, 29, 32, 35, 38–40, 42–43
   manifest_output.py82820%1–5, 9, 12–13, 16, 34, 50–53, 56–57, 61–62, 67–68, 76, 79–83, 86–92, 94, 112–113, 118, 120–121, 126, 129, 131, 133, 135, 139, 149, 154–155, 161, 164–165, 167–168, 174–177, 183–185, 187, 194, 196, 201, 203–205, 207–208, 210–211, 213–216, 218, 221, 223, 229–230, 233–234
   map_output_cols.py38781%150–151, 153, 155, 158, 161, 163
   ni_sas.py19190%2–8, 10, 13, 26, 29, 32, 35, 40, 43–45, 48–49
   outputs_helpers.py170100% 
   outputs_main.py83830%3–4, 7, 10–22, 24, 27, 49, 54–56, 61, 64, 67–69, 74, 77–78, 81–83, 89, 92–94, 100, 103–105, 107–108, 113, 116–118, 127, 130–132, 136–137, 146, 149–151, 158, 161–163, 167–168, 176, 179–181, 188, 191–193, 198, 201–203, 210, 213–215, 217–219, 221
   short_form.py341361%78, 85, 87, 104, 107, 110, 113, 116, 119–121, 123–124
   tau.py25250%2–8, 10, 13, 30, 34, 37, 40, 43, 46, 51, 54, 56–57, 60–62, 65–66, 68
   total_fte.py12120%2–5, 8, 11, 26, 28–29, 35, 40–41
src/site_apportionment
   __init__.py00100% 
   output_status_filtered.py261542%25, 27, 31–32, 34–35, 37, 44–45, 72, 75, 77, 79–80, 82
   site_apportionment.py126397%467, 469–470
   site_apportionment_main.py25250%3–5, 7–8, 12, 14, 17, 39–40, 43, 45, 48–49, 57–58, 60–61, 64, 69–72, 74–75
src/staging
   __init__.py00100% 
   postcode_validation.py56394%131–132, 220
   spp_parser.py140100% 
   spp_snapshot_processing.py340100% 
   staging_helpers.py861582%173, 176, 178, 181–182, 185–186, 188–189, 192, 196–197, 199, 203, 209
   staging_main.py98980%3–5, 7, 9–11, 15, 18, 64–66, 69, 71, 75–77, 79–80, 84, 86–87, 90, 93, 96–97, 99–100, 105–107, 111–114, 116–117, 123, 128–130, 132–133, 136, 148–150, 155, 158, 162, 164, 166–168, 171, 175, 177, 179–183, 186, 189, 191–192, 195, 197, 200–204, 207, 211–212, 215–219, 221, 224, 232, 241–242, 244–249, 251, 253–254, 256, 259, 270
   validation.py1434965%34–36, 39, 42, 88–89, 100, 122, 135–136, 141, 145, 153–154, 160–161, 200–201, 207, 209, 212, 214, 221–222, 301, 303–304, 307–308, 311–312, 315, 318–319, 322, 324, 326–327, 341, 343–349, 352, 355
src/utils
   __init__.py00100% 
   breakdown_validation.py1304565%29, 186–188, 190–194, 196, 198, 201–202, 208–209, 212, 215, 217, 220, 222, 234–237, 240–243, 259–260, 265, 308–309, 311, 317–318, 360–363, 365–368, 371
   config.py149298%152–153
   defence.py200100% 
   helpers.py731875%19–20, 24–25, 27, 134–137, 139–140, 143–145, 154, 156–157, 215
   local_file_mods.py1204760%47–53, 98, 148–150, 199–203, 214–215, 226, 237, 248–249, 251, 262–263, 274–275, 284, 292, 303, 305–306, 308–309, 313–315, 319, 333–334, 336–337, 340–341, 343, 360, 365
   path_helpers.py142894%96, 311, 313, 315–316, 318–319, 321
   postcode_reduction_helper.py38380%11, 13–14, 16, 19, 21, 24, 26–27, 29–30, 33–34, 37, 39–40, 42–43, 46, 59, 61, 64, 67, 70–71, 73–74, 76, 79, 94, 96, 99–100, 103–104, 106, 108–109
   s3_mods.py1271270%19–20, 22–23, 25, 33, 38–40, 44, 58, 60–61, 64–67, 69–70, 73, 84, 87, 92, 95–96, 99, 110–111, 113, 116, 130, 132–133, 135, 138, 148, 155, 158, 160, 163, 165, 168, 179–180, 182, 185, 193–194, 197, 206–211, 214, 225–226, 229–230, 233, 236, 239, 250–251, 253–256, 258–259, 262, 268, 271, 284, 287, 290, 292, 295, 301, 304, 307–308, 311, 319–321, 323, 326, 330–331, 333, 336, 365, 369, 371, 378, 381, 386–388, 395, 398, 413, 415–416, 418–419, 423, 425, 427, 430, 432–434, 436, 439, 449, 452–453, 456, 459, 461–462, 464–466
   singleton_boto.py20200%4–5, 8–10, 12–13, 15–22, 24–28
TOTAL3987193851% 

Summary of tests

Tests Skipped Failures Errors Time
264 2 💤 0 ❌ 0 🔥 3.334s ⏱️

Copy link
Collaborator

@Ryan2Y79 Ryan2Y79 left a comment

Choose a reason for hiding this comment

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

Its great you added a unit test for populate_instance_1_columns :D

Just 2 comments to address. Cheers.

helpers/create_pnp_backdata.py Outdated Show resolved Hide resolved
helpers/create_pnp_backdata.py Outdated Show resolved Hide resolved
@Ryan2Y79
Copy link
Collaborator

@AnneONS According to D:\research-and-development\config\backdata_schema.toml the 604 column needs to be in float format, and not populated with strings! This is the ONLY schema issue with the PNP backdata.

Copy link
Collaborator

@adriano-lopresti adriano-lopresti left a comment

Choose a reason for hiding this comment

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

I am happy with the changes - PR ready to be merged

@AnneONS AnneONS dismissed Ryan2Y79’s stale review January 6, 2025 11:30

it is out of date

@AnneONS AnneONS merged commit ad824ca into develop Jan 6, 2025
1 check passed
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.

3 participants