|
27 | 27 | from astropy.table.column import BaseColumn |
28 | 28 | from astropy.table.serialize import represent_mixins_as_columns |
29 | 29 | from astropy.table.table_helpers import ArrayWrapper |
| 30 | +from astropy.utils.compat import NUMPY_LT_2_0 |
30 | 31 | from astropy.utils.data_info import ParentDtypeInfo |
31 | 32 | from astropy.utils.exceptions import AstropyUserWarning |
32 | 33 | from astropy.utils.metadata import MergeConflictWarning |
@@ -756,56 +757,98 @@ def test_quantity_representation(): |
756 | 757 | ] |
757 | 758 |
|
758 | 759 |
|
759 | | -def test_representation_representation(): |
| 760 | +@pytest.mark.parametrize( |
| 761 | + "data, pformat", |
| 762 | + [ |
| 763 | + ( |
| 764 | + coordinates.CartesianRepresentation([0], [1], [0], unit=u.one), |
| 765 | + [ |
| 766 | + " col0 ", |
| 767 | + "------------", |
| 768 | + "(0., 1., 0.)", |
| 769 | + ] |
| 770 | + if NUMPY_LT_2_0 |
| 771 | + else [ |
| 772 | + " col0 ", |
| 773 | + "---------------", |
| 774 | + "(0.0, 1.0, 0.0)", |
| 775 | + ], |
| 776 | + ), |
| 777 | + ( |
| 778 | + coordinates.CartesianRepresentation([0], [1], [0], unit="m"), |
| 779 | + [ |
| 780 | + " col0 ", |
| 781 | + " m ", |
| 782 | + "------------", |
| 783 | + "(0., 1., 0.)", |
| 784 | + ] |
| 785 | + if NUMPY_LT_2_0 |
| 786 | + else [ |
| 787 | + " col0 ", |
| 788 | + " m ", |
| 789 | + "---------------", |
| 790 | + "(0.0, 1.0, 0.0)", |
| 791 | + ], |
| 792 | + ), |
| 793 | + ( |
| 794 | + coordinates.SphericalRepresentation([10] * u.deg, [20] * u.deg, [1] * u.pc), |
| 795 | + [ |
| 796 | + " col0 ", |
| 797 | + " deg, deg, pc ", |
| 798 | + "--------------", |
| 799 | + "(10., 20., 1.)", |
| 800 | + ] |
| 801 | + if NUMPY_LT_2_0 |
| 802 | + else [ |
| 803 | + " col0 ", |
| 804 | + " deg, deg, pc ", |
| 805 | + "-----------------", |
| 806 | + "(10.0, 20.0, 1.0)", |
| 807 | + ], |
| 808 | + ), |
| 809 | + ( |
| 810 | + coordinates.UnitSphericalRepresentation([10] * u.deg, [20] * u.deg), |
| 811 | + [ |
| 812 | + " col0 ", |
| 813 | + " deg ", |
| 814 | + "----------", |
| 815 | + "(10., 20.)", |
| 816 | + ] |
| 817 | + if NUMPY_LT_2_0 |
| 818 | + else [ |
| 819 | + " col0 ", |
| 820 | + " deg ", |
| 821 | + "------------", |
| 822 | + "(10.0, 20.0)", |
| 823 | + ], |
| 824 | + ), |
| 825 | + ( |
| 826 | + coordinates.SphericalCosLatDifferential( |
| 827 | + [10] * u.mas / u.yr, [2] * u.mas / u.yr, [10] * u.km / u.s |
| 828 | + ), |
| 829 | + [ |
| 830 | + " col0 ", |
| 831 | + "mas / yr, mas / yr, km / s", |
| 832 | + "--------------------------", |
| 833 | + " (10., 2., 10.)", |
| 834 | + ] |
| 835 | + if NUMPY_LT_2_0 |
| 836 | + else [ |
| 837 | + " col0 ", |
| 838 | + "mas / yr, mas / yr, km / s", |
| 839 | + "--------------------------", |
| 840 | + " (10.0, 2.0, 10.0)", |
| 841 | + ], |
| 842 | + ), |
| 843 | + ], |
| 844 | +) |
| 845 | +def test_representation_representation(data, pformat): |
760 | 846 | """ |
761 | 847 | Test that Representations are represented correctly. |
762 | 848 | """ |
763 | 849 | # With no unit we get "None" in the unit row |
764 | | - c = coordinates.CartesianRepresentation([0], [1], [0], unit=u.one) |
765 | | - t = Table([c]) |
766 | | - assert t.pformat() == [ |
767 | | - " col0 ", |
768 | | - "------------", |
769 | | - "(0., 1., 0.)", |
770 | | - ] |
771 | | - |
772 | | - c = coordinates.CartesianRepresentation([0], [1], [0], unit="m") |
773 | | - t = Table([c]) |
774 | | - assert t.pformat() == [ |
775 | | - " col0 ", |
776 | | - " m ", |
777 | | - "------------", |
778 | | - "(0., 1., 0.)", |
779 | | - ] |
780 | | - |
781 | | - c = coordinates.SphericalRepresentation([10] * u.deg, [20] * u.deg, [1] * u.pc) |
782 | | - t = Table([c]) |
783 | | - assert t.pformat() == [ |
784 | | - " col0 ", |
785 | | - " deg, deg, pc ", |
786 | | - "--------------", |
787 | | - "(10., 20., 1.)", |
788 | | - ] |
789 | | - |
790 | | - c = coordinates.UnitSphericalRepresentation([10] * u.deg, [20] * u.deg) |
791 | | - t = Table([c]) |
792 | | - assert t.pformat() == [ |
793 | | - " col0 ", |
794 | | - " deg ", |
795 | | - "----------", |
796 | | - "(10., 20.)", |
797 | | - ] |
798 | | - |
799 | | - c = coordinates.SphericalCosLatDifferential( |
800 | | - [10] * u.mas / u.yr, [2] * u.mas / u.yr, [10] * u.km / u.s |
801 | | - ) |
802 | | - t = Table([c]) |
803 | | - assert t.pformat() == [ |
804 | | - " col0 ", |
805 | | - "mas / yr, mas / yr, km / s", |
806 | | - "--------------------------", |
807 | | - " (10., 2., 10.)", |
808 | | - ] |
| 850 | + t = Table([data]) |
| 851 | + assert t.pformat() == pformat |
809 | 852 |
|
810 | 853 |
|
811 | 854 | def test_skycoord_representation(): |
@@ -916,15 +959,27 @@ def test_ndarray_mixin(as_ndarray_mixin): |
916 | 959 | assert t[1]["d"][0] == d[1][0] |
917 | 960 | assert t[1]["d"][1] == d[1][1] |
918 | 961 |
|
919 | | - assert t.pformat(show_dtype=True) == [ |
920 | | - " a [f0, f1] b [x, y] c [rx, ry] d ", |
921 | | - "(int32, str1) (int32, str2) (float64, str3) int64[2]", |
922 | | - "------------- ------------- --------------- --------", |
923 | | - " (1, 'a') (10, 'aa') (100., 'raa') 0 .. 1", |
924 | | - " (2, 'b') (20, 'bb') (200., 'rbb') 2 .. 3", |
925 | | - " (3, 'c') (30, 'cc') (300., 'rcc') 4 .. 5", |
926 | | - " (4, 'd') (40, 'dd') (400., 'rdd') 6 .. 7", |
927 | | - ] |
| 962 | + assert ( |
| 963 | + t.pformat(show_dtype=True) |
| 964 | + == [ |
| 965 | + " a [f0, f1] b [x, y] c [rx, ry] d ", |
| 966 | + "(int32, str1) (int32, str2) (float64, str3) int64[2]", |
| 967 | + "------------- ------------- --------------- --------", |
| 968 | + ] |
| 969 | + + [ |
| 970 | + " (1, 'a') (10, 'aa') (100., 'raa') 0 .. 1", |
| 971 | + " (2, 'b') (20, 'bb') (200., 'rbb') 2 .. 3", |
| 972 | + " (3, 'c') (30, 'cc') (300., 'rcc') 4 .. 5", |
| 973 | + " (4, 'd') (40, 'dd') (400., 'rdd') 6 .. 7", |
| 974 | + ] |
| 975 | + if NUMPY_LT_2_0 |
| 976 | + else [ |
| 977 | + " (1, 'a') (10, 'aa') (100.0, 'raa') 0 .. 1", |
| 978 | + " (2, 'b') (20, 'bb') (200.0, 'rbb') 2 .. 3", |
| 979 | + " (3, 'c') (30, 'cc') (300.0, 'rcc') 4 .. 5", |
| 980 | + " (4, 'd') (40, 'dd') (400.0, 'rdd') 6 .. 7", |
| 981 | + ] |
| 982 | + ) |
928 | 983 |
|
929 | 984 |
|
930 | 985 | def test_possible_string_format_functions(): |
|
0 commit comments