This is a helper function of loadtxt and genfromtxt to ensure proper minimum dimension as requested ndim : int. Supported values 1, 2, 3 ^^ whenever this changes, keep in sync with _ensure_ndmin_ndarray_check_param
(a, *, ndmin: int)
| 801 | raise ValueError(f"Illegal value of ndmin keyword: {ndmin}") |
| 802 | |
| 803 | def _ensure_ndmin_ndarray(a, *, ndmin: int): |
| 804 | """This is a helper function of loadtxt and genfromtxt to ensure |
| 805 | proper minimum dimension as requested |
| 806 | |
| 807 | ndim : int. Supported values 1, 2, 3 |
| 808 | ^^ whenever this changes, keep in sync with |
| 809 | _ensure_ndmin_ndarray_check_param |
| 810 | """ |
| 811 | # Verify that the array has at least dimensions `ndmin`. |
| 812 | # Tweak the size and shape of the arrays - remove extraneous dimensions |
| 813 | if a.ndim > ndmin: |
| 814 | a = np.squeeze(a) |
| 815 | # and ensure we have the minimum number of dimensions asked for |
| 816 | # - has to be in this order for the odd case ndmin=1, a.squeeze().ndim=0 |
| 817 | if a.ndim < ndmin: |
| 818 | if ndmin == 1: |
| 819 | a = np.atleast_1d(a) |
| 820 | elif ndmin == 2: |
| 821 | a = np.atleast_2d(a).T |
| 822 | |
| 823 | return a |
| 824 | |
| 825 | |
| 826 | # amount of lines loadtxt reads in one chunk, can be overridden for testing |
no test coverage detected
searching dependent graphs…