Commit 1383ce9
committed
refactor(waterdata): simplify get_waterdata internals
Code-review pass on PR DOI-USGS#284.
- Lift ``WATERDATA_SERVICES`` Literal into ``types.py``. Use it as
the ``service`` arg type of ``get_waterdata`` so editors offer
completion and type-checkers catch typos. The runtime source of
truth (``_OUTPUT_ID_BY_SERVICE`` in utils.py) is unchanged; the
Literal is kept in sync by hand and a comment notes that.
- Extract ``_ogc_query_params(properties, bbox, limit, skip_geometry)``
in utils.py. The same ``skipGeometry``/``limit``/``bbox``/``properties``
block previously appeared twice — once in ``_construct_api_requests``
and once in the new ``_construct_cql_request`` — and is now built
in one place.
- Extract ``_finalize_ogc_frame(df, response, properties, service,
output_id, convert_type)`` for the post-processing tail
(``_deal_with_empty`` -> ``_type_cols`` -> ``_arrange_cols`` ->
``_sort_rows`` -> ``BaseMetadata``). Both ``get_ogc_data`` and
``get_waterdata`` route through it now, so the typed-kwargs and
raw-CQL2 paths produce identically-shaped DataFrames by
construction rather than by parallel maintenance.
- Drop the ``client`` kwarg from ``get_waterdata``. None of the
other public ``get_*`` getters expose it, and the rationale (HTTP
session reuse) applies to all of them or none. If we want to
expose session reuse, that's a separate PR that touches the whole
family.
- Collapse the ``properties`` normalization block to None-first
ordering so the common case (no properties) reads first.
- Drop the docstring breadcrumb to ``utils._OUTPUT_ID_BY_SERVICE``;
point readers at ``types.WATERDATA_SERVICES`` (the user-facing
Literal) instead.
All 148 unit tests pass; ``_construct_api_requests`` and
``_construct_cql_request`` produce byte-identical requests to before.1 parent dffb168 commit 1383ce9
3 files changed
Lines changed: 89 additions & 76 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | 35 | | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | | - | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
2845 | 2843 | | |
2846 | 2844 | | |
2847 | 2845 | | |
2848 | | - | |
| 2846 | + | |
2849 | 2847 | | |
2850 | 2848 | | |
2851 | 2849 | | |
2852 | 2850 | | |
2853 | 2851 | | |
2854 | 2852 | | |
2855 | 2853 | | |
2856 | | - | |
2857 | 2854 | | |
2858 | 2855 | | |
2859 | 2856 | | |
| |||
2871 | 2868 | | |
2872 | 2869 | | |
2873 | 2870 | | |
2874 | | - | |
2875 | | - | |
2876 | | - | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
2877 | 2874 | | |
2878 | 2875 | | |
2879 | 2876 | | |
| |||
2886 | 2883 | | |
2887 | 2884 | | |
2888 | 2885 | | |
2889 | | - | |
| 2886 | + | |
| 2887 | + | |
2890 | 2888 | | |
2891 | 2889 | | |
2892 | 2890 | | |
| |||
2895 | 2893 | | |
2896 | 2894 | | |
2897 | 2895 | | |
2898 | | - | |
2899 | | - | |
2900 | | - | |
2901 | | - | |
2902 | 2896 | | |
2903 | 2897 | | |
2904 | 2898 | | |
| |||
2934 | 2928 | | |
2935 | 2929 | | |
2936 | 2930 | | |
2937 | | - | |
2938 | | - | |
2939 | | - | |
2940 | | - | |
2941 | | - | |
| 2931 | + | |
2942 | 2932 | | |
2943 | 2933 | | |
2944 | 2934 | | |
| |||
2961 | 2951 | | |
2962 | 2952 | | |
2963 | 2953 | | |
2964 | | - | |
2965 | | - | |
2966 | | - | |
| 2954 | + | |
2967 | 2955 | | |
| 2956 | + | |
| 2957 | + | |
2968 | 2958 | | |
2969 | 2959 | | |
2970 | 2960 | | |
| |||
2983 | 2973 | | |
2984 | 2974 | | |
2985 | 2975 | | |
2986 | | - | |
2987 | | - | |
2988 | | - | |
2989 | | - | |
2990 | | - | |
2991 | | - | |
2992 | | - | |
2993 | | - | |
2994 | | - | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
43 | 63 | | |
44 | 64 | | |
45 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
512 | 512 | | |
513 | 513 | | |
514 | 514 | | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
| 515 | + | |
523 | 516 | | |
524 | 517 | | |
525 | 518 | | |
| |||
548 | 541 | | |
549 | 542 | | |
550 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
551 | 564 | | |
552 | 565 | | |
553 | 566 | | |
| |||
558 | 571 | | |
559 | 572 | | |
560 | 573 | | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
582 | 579 | | |
583 | 580 | | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | 581 | | |
593 | 582 | | |
594 | 583 | | |
595 | 584 | | |
596 | 585 | | |
597 | 586 | | |
598 | 587 | | |
599 | | - | |
| 588 | + | |
600 | 589 | | |
601 | 590 | | |
602 | 591 | | |
| |||
941 | 930 | | |
942 | 931 | | |
943 | 932 | | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
944 | 956 | | |
945 | 957 | | |
946 | 958 | | |
| |||
987 | 999 | | |
988 | 1000 | | |
989 | 1001 | | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
997 | 1005 | | |
998 | 1006 | | |
999 | 1007 | | |
| |||
0 commit comments