Return a Cycler object from a string repr or the object itself.
(s)
| 919 | |
| 920 | |
| 921 | def validate_cycler(s): |
| 922 | """Return a Cycler object from a string repr or the object itself.""" |
| 923 | if isinstance(s, str): |
| 924 | try: |
| 925 | s = _parse_cycler_string(s) |
| 926 | except Exception as e: |
| 927 | raise ValueError(f"{s!r} is not a valid cycler construction: {e}" |
| 928 | ) from e |
| 929 | if isinstance(s, Cycler): |
| 930 | cycler_inst = s |
| 931 | else: |
| 932 | raise ValueError(f"Object is not a string or Cycler instance: {s!r}") |
| 933 | |
| 934 | unknowns = cycler_inst.keys - (set(_prop_validators) | set(_prop_aliases)) |
| 935 | if unknowns: |
| 936 | raise ValueError("Unknown artist properties: %s" % unknowns) |
| 937 | |
| 938 | # Not a full validation, but it'll at least normalize property names |
| 939 | # A fuller validation would require v0.10 of cycler. |
| 940 | checker = set() |
| 941 | for prop in cycler_inst.keys: |
| 942 | norm_prop = _prop_aliases.get(prop, prop) |
| 943 | if norm_prop != prop and norm_prop in cycler_inst.keys: |
| 944 | raise ValueError(f"Cannot specify both {norm_prop!r} and alias " |
| 945 | f"{prop!r} in the same prop_cycle") |
| 946 | if norm_prop in checker: |
| 947 | raise ValueError(f"Another property was already aliased to " |
| 948 | f"{norm_prop!r}. Collision normalizing {prop!r}.") |
| 949 | checker.update([norm_prop]) |
| 950 | |
| 951 | # This is just an extra-careful check, just in case there is some |
| 952 | # edge-case I haven't thought of. |
| 953 | assert len(checker) == len(cycler_inst.keys) |
| 954 | |
| 955 | # Now, it should be safe to mutate this cycler |
| 956 | for prop in cycler_inst.keys: |
| 957 | norm_prop = _prop_aliases.get(prop, prop) |
| 958 | cycler_inst.change_key(prop, norm_prop) |
| 959 | |
| 960 | for key, vals in cycler_inst.by_key().items(): |
| 961 | _prop_validators[key](vals) |
| 962 | |
| 963 | return cycler_inst |
| 964 | |
| 965 | |
| 966 | def validate_hist_bins(s): |
searching dependent graphs…