(self)
| 149 | np.fromfile(path, dtype=float, sep=" ") |
| 150 | |
| 151 | def test_fromfile_complex(self): |
| 152 | for ctype in ["complex", "cdouble"]: |
| 153 | # Check spacing between separator and only real component specified |
| 154 | with temppath() as path: |
| 155 | with open(path, 'w') as f: |
| 156 | f.write("1, 2 , 3 ,4\n") |
| 157 | |
| 158 | res = np.fromfile(path, dtype=ctype, sep=",") |
| 159 | assert_equal(res, np.array([1., 2., 3., 4.])) |
| 160 | |
| 161 | # Real component not specified |
| 162 | with temppath() as path: |
| 163 | with open(path, 'w') as f: |
| 164 | f.write("1j, -2j, 3j, 4e1j\n") |
| 165 | |
| 166 | res = np.fromfile(path, dtype=ctype, sep=",") |
| 167 | assert_equal(res, np.array([1.j, -2.j, 3.j, 40.j])) |
| 168 | |
| 169 | # Both components specified |
| 170 | with temppath() as path: |
| 171 | with open(path, 'w') as f: |
| 172 | f.write("1+1j,2-2j, -3+3j, -4e1+4j\n") |
| 173 | |
| 174 | res = np.fromfile(path, dtype=ctype, sep=",") |
| 175 | assert_equal(res, np.array([1. + 1.j, 2. - 2.j, - 3. + 3.j, - 40. + 4j])) |
| 176 | |
| 177 | # Spaces at wrong places |
| 178 | with temppath() as path: |
| 179 | with open(path, 'w') as f: |
| 180 | f.write("1+2 j,3\n") |
| 181 | |
| 182 | with assert_raises(ValueError): |
| 183 | np.fromfile(path, dtype=ctype, sep=",") |
| 184 | |
| 185 | # Spaces at wrong places |
| 186 | with temppath() as path: |
| 187 | with open(path, 'w') as f: |
| 188 | f.write("1+ 2j,3\n") |
| 189 | |
| 190 | with assert_raises(ValueError): |
| 191 | np.fromfile(path, dtype=ctype, sep=",") |
| 192 | |
| 193 | # Spaces at wrong places |
| 194 | with temppath() as path: |
| 195 | with open(path, 'w') as f: |
| 196 | f.write("1 +2j,3\n") |
| 197 | |
| 198 | with assert_raises(ValueError): |
| 199 | np.fromfile(path, dtype=ctype, sep=",") |
| 200 | |
| 201 | # Wrong sep |
| 202 | with temppath() as path: |
| 203 | with open(path, 'w') as f: |
| 204 | f.write("1+j\n") |
| 205 | |
| 206 | with assert_raises(ValueError): |
| 207 | np.fromfile(path, dtype=ctype, sep=",") |
| 208 |
nothing calls this directly
no test coverage detected