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)
| 758 | raise ValueError(f"Illegal value of ndmin keyword: {ndmin}") |
| 759 | |
| 760 | def _ensure_ndmin_ndarray(a, *, ndmin: int): |
| 761 | """This is a helper function of loadtxt and genfromtxt to ensure |
| 762 | proper minimum dimension as requested |
| 763 | |
| 764 | ndim : int. Supported values 1, 2, 3 |
| 765 | ^^ whenever this changes, keep in sync with |
| 766 | _ensure_ndmin_ndarray_check_param |
| 767 | """ |
| 768 | # Verify that the array has at least dimensions `ndmin`. |
| 769 | # Tweak the size and shape of the arrays - remove extraneous dimensions |
| 770 | if a.ndim > ndmin: |
| 771 | a = np.squeeze(a) |
| 772 | # and ensure we have the minimum number of dimensions asked for |
| 773 | # - has to be in this order for the odd case ndmin=1, a.squeeze().ndim=0 |
| 774 | if a.ndim < ndmin: |
| 775 | if ndmin == 1: |
| 776 | a = np.atleast_1d(a) |
| 777 | elif ndmin == 2: |
| 778 | a = np.atleast_2d(a).T |
| 779 | |
| 780 | return a |
| 781 | |
| 782 | |
| 783 | # amount of lines loadtxt reads in one chunk, can be overridden for testing |
no test coverage detected