module documentation

Tests specific to np.loadtxt added during the move of loadtxt to be backed by C code. These tests complement those found in test_io.py.

Class TestCReaderUnitTests Undocumented
Function mixed_types_structured Fixture providing hetergeneous input data with a structured dtype, along with the associated structured array.
Function test_bad_complex Undocumented
Function test_bad_ndmin Undocumented
Function test_bad_newline_in_iterator Undocumented
Function test_blank_lines_normal_delimiter Undocumented
Function test_blank_lines_spaces_delimit Undocumented
Function test_bool Undocumented
Function test_byteswapping_and_unaligned Undocumented
Function test_character_not_bytes_compatible Test exception when a character cannot be encoded as 'S'.
Function test_collision_with_default_delimiter_raises Undocumented
Function test_comment_multichar_error_with_quote Undocumented
Function test_comment_multiple_chars Undocumented
Function test_comment_quotechar_collision_raises Undocumented
Function test_complex_parsing Undocumented
Function test_consecutive_quotechar_escaped Undocumented
Function test_control_character_empty Undocumented
Function test_control_character_newline_raises Undocumented
Function test_control_characters_as_bytes Byte control characters (comments, delimiter) are supported.
Function test_converter_with_structured_dtype Undocumented
Function test_converter_with_unicode_dtype With the default 'bytes' encoding, tokens are encoded prior to being passed to the converter. This means that the output of the converter may be bytes instead of unicode as expected by read_rows.
Function test_converters_dict_raises_non_col_key Undocumented
Function test_converters_dict_raises_non_integer_key Undocumented
Function test_converters_dict_raises_val_not_callable Undocumented
Function test_converters_negative_indices Undocumented
Function test_converters_negative_indices_with_usecols Undocumented
Function test_delimiter_and_multiple_comments_collision_raises Undocumented
Function test_delimiter_comment_collision_raises Undocumented
Function test_delimiter_quotechar_collision_raises Undocumented
Function test_empty_usecols Undocumented
Function test_exception_message_bad_values Undocumented
Function test_exception_negative_row_limits skiprows and max_rows should raise for negative parameters.
Function test_exception_noninteger_row_limits Undocumented
Function test_field_growing_cases Undocumented
Function test_float_conversion Some tests that the conversion to float64 works as accurately as the Python built-in float function. In a naive version of the float parser, these strings resulted in values that were off by an ULP or two.
Function test_good_newline_in_iterator Undocumented
Function test_huge_float Undocumented
Function test_implicit_cast_float_to_int_fails Undocumented
Function test_integer_signs Undocumented
Function test_invalid_converter Undocumented
Function test_iterator_fails_getting_next_line Undocumented
Function test_large_unicode_characters Undocumented
Function test_maxrows_no_blank_lines Undocumented
Function test_ndmin_single_row_or_col Undocumented
Function test_nested_structured_subarray Undocumented
Function test_no_thousands_support Undocumented
Function test_nul_character_error Undocumented
Function test_null_character Undocumented
Function test_object_cleanup_on_read_error Undocumented
Function test_parametric_unit_discovery Check that the correct unit (e.g. month, day, second) is discovered from the data when a user specifies a unitless datetime.
Function test_quote_support_default Support for quoted fields is disabled by default.
Function test_quotechar_multichar_error Undocumented
Function test_quoted_field Undocumented
Function test_quoted_field_is_not_empty Undocumented
Function test_quoted_field_is_not_empty_nonstrict Undocumented
Function test_quoted_field_with_whitepace_delimiter Undocumented
Function test_ragged_usecols Undocumented
Function test_read_from_bad_generator Undocumented
Function test_read_from_generator Undocumented
Function test_read_from_generator_multitype Undocumented
Function test_read_huge_row Undocumented
Function test_scientific_notation Test that both 'e' and 'E' are parsed correctly.
Function test_str_dtype_unit_discovery_with_converter Undocumented
Function test_string_no_length_given The given dtype is just 'S' or 'U' with no length. In these cases, the length of the resulting dtype is determined by the longest string found in the file.
Function test_structured_dtype_and_skiprows_no_empty_lines Undocumented
Function test_structured_dtype_offsets Undocumented
Function test_structured_dtype_with_multi_shape Undocumented
Function test_structured_dtype_with_quotes Undocumented
Function test_structured_dtype_with_shape Undocumented
Function test_unicode_whitespace_stripping Undocumented
Function test_unicode_whitespace_stripping_complex Undocumented
Function test_unicode_with_converter Undocumented
Function test_universal_newlines_quoted Undocumented
Function test_unpack_structured Undocumented
Function test_warn_on_no_data Check that a UserWarning is emitted when no data is read from input.
Function test_warn_on_skipped_data Undocumented
@pytest.fixture
def mixed_types_structured(): (source)

Fixture providing hetergeneous input data with a structured dtype, along with the associated structured array.

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
@pytest.mark.parametrize('dtype', 'FD')
@pytest.mark.parametrize('field', ['1 +2j', '1+ 2j', '1+2 j', '1+-+3', '(1j', '(1', '(1+2j', '1+2j)'])
def test_bad_complex(dtype, field): (source)

Undocumented

@pytest.mark.parametrize('badval', [-1, 3, None, 'plate of shrimp'])
def test_bad_ndmin(badval): (source)

Undocumented

@pytest.mark.parametrize('data', [['1,2\n', '2\n,3\n'], ['1,2\n', '2\r,3\n']])
def test_bad_newline_in_iterator(data): (source)

Undocumented

def test_blank_lines_normal_delimiter(): (source)

Undocumented

@pytest.mark.parametrize('ws', (' ', '\t', ' ', ' ', ' '))
def test_blank_lines_spaces_delimit(ws): (source)

Undocumented

def test_bool(): (source)

Undocumented

@pytest.mark.parametrize(['dtype', 'value'], [('i2', 1), ('u2', 1), ('i4', 66051), ('u4', 66051), ('i8', 283686952306183), ('u8', 283686952306183), ('float16', 3.07e-05), ('float32', 9.2557e-41), ('complex64', 9.2557e-41+2.8622554e-29j), ('float64', -1.758571353180402e-24), ('complex128', repr(5.406409232372729e-29-1.758571353180402e-24j)), ('longdouble', 283686952306183), ('clongdouble', repr(283686952306183+19873150604823*1j)), ('U2', '𐈃򠬌')])
@pytest.mark.parametrize('swap', [True, False])
def test_byteswapping_and_unaligned(dtype, value, swap): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
def test_character_not_bytes_compatible(): (source)

Test exception when a character cannot be encoded as 'S'.

@pytest.mark.parametrize('ws', (' ', '\t', ' ', ' ', ' '))
def test_collision_with_default_delimiter_raises(ws): (source)

Undocumented

def test_comment_multichar_error_with_quote(): (source)

Undocumented

@pytest.mark.parametrize('comment', ['..', '//', '@-', 'this is a comment:'])
def test_comment_multiple_chars(comment): (source)

Undocumented

def test_comment_quotechar_collision_raises(): (source)

Undocumented

@pytest.mark.parametrize('dtype', (np.complex64, np.complex128))
@pytest.mark.parametrize('with_parens', (False, True))
def test_complex_parsing(dtype, with_parens): (source)

Undocumented

def test_consecutive_quotechar_escaped(): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
def test_control_character_empty(): (source)

Undocumented

@pytest.mark.parametrize('nl', ('\n', '\r'))
def test_control_character_newline_raises(nl): (source)

Undocumented

def test_control_characters_as_bytes(): (source)

Byte control characters (comments, delimiter) are supported.

def test_converter_with_structured_dtype(): (source)

Undocumented

def test_converter_with_unicode_dtype(): (source)

With the default 'bytes' encoding, tokens are encoded prior to being passed to the converter. This means that the output of the converter may be bytes instead of unicode as expected by read_rows.

This test checks that outputs from the above scenario are properly decoded prior to parsing by read_rows.

@pytest.mark.parametrize('bad_col_ind', (3, -3))
def test_converters_dict_raises_non_col_key(bad_col_ind): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
def test_converters_dict_raises_non_integer_key(): (source)

Undocumented

def test_converters_dict_raises_val_not_callable(): (source)

Undocumented

def test_converters_negative_indices(): (source)

Undocumented

def test_converters_negative_indices_with_usecols(): (source)

Undocumented

def test_delimiter_and_multiple_comments_collision_raises(): (source)

Undocumented

def test_delimiter_comment_collision_raises(): (source)

Undocumented

def test_delimiter_quotechar_collision_raises(): (source)

Undocumented

def test_empty_usecols(): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
@pytest.mark.parametrize('dtype', (np.dtype('f8'), np.dtype('i2')))
def test_exception_message_bad_values(dtype): (source)

Undocumented

@pytest.mark.parametrize('param', ('skiprows', 'max_rows'))
def test_exception_negative_row_limits(param): (source)

skiprows and max_rows should raise for negative parameters.

@pytest.mark.parametrize('param', ('skiprows', 'max_rows'))
def test_exception_noninteger_row_limits(param): (source)

Undocumented

@pytest.mark.filterwarnings('ignore::UserWarning')
def test_field_growing_cases(): (source)

Undocumented

def test_float_conversion(): (source)

Some tests that the conversion to float64 works as accurately as the Python built-in float function. In a naive version of the float parser, these strings resulted in values that were off by an ULP or two.

@pytest.mark.parametrize('data', [['1,2\n', '2,3\r\n'], ['1,2\n', '\'2\n\',3\n'], ['1,2\n', '\'2\r\',3\n'], ['1,2\n', '\'2\r\n\',3\n']])
def test_good_newline_in_iterator(data): (source)

Undocumented

@pytest.mark.parametrize('dtype', 'edfgFDG')
def test_huge_float(dtype): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
@pytest.mark.parametrize('dtype', np.typecodes['AllInteger'])
@pytest.mark.filterwarnings('error:.*integer via a float.*:DeprecationWarning')
def test_implicit_cast_float_to_int_fails(dtype): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
@pytest.mark.parametrize('dtype', np.typecodes['AllInteger'])
@pytest.mark.filterwarnings('error:.*integer via a float.*:DeprecationWarning')
def test_integer_signs(dtype): (source)

Undocumented

@pytest.mark.parametrize('conv', (0, [float], ''))
def test_invalid_converter(conv): (source)

Undocumented

def test_iterator_fails_getting_next_line(): (source)

Undocumented

@pytest.mark.parametrize('c1', ['a', '', '🫕'])
@pytest.mark.parametrize('c2', ['a', '', '🫕'])
def test_large_unicode_characters(c1, c2): (source)

Undocumented

@pytest.mark.parametrize('dtype', (float, object))
def test_maxrows_no_blank_lines(dtype): (source)

Undocumented

@pytest.mark.parametrize('data, shape', [('1 2 3 4 5\n', (1, 5)), ('1\n2\n3\n4\n5\n', (5, 1))])
def test_ndmin_single_row_or_col(data, shape): (source)

Undocumented

def test_nested_structured_subarray(): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
@pytest.mark.parametrize('dtype', (np.typecodes['AllInteger']+'efgdFDG')+'?')
def test_no_thousands_support(dtype): (source)

Undocumented

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
@pytest.mark.parametrize('dtype', (np.typecodes['AllInteger']+'efgdFDG')+'?')
def test_nul_character_error(dtype): (source)

Undocumented

def test_null_character(): (source)

Undocumented

@pytest.mark.skipif(not HAS_REFCOUNT, reason='Python lacks refcounts')
def test_object_cleanup_on_read_error(): (source)

Undocumented

@pytest.mark.parametrize(('generic_data', 'long_datum', 'unitless_dtype', 'expected_dtype'), [('2012-03', '2013-01-15', 'M8', 'M8[D]'), ('spam-a-lot', 'tis_but_a_scratch', 'U', 'U17')])
@pytest.mark.parametrize('nrows', (10, 50000, 60000))
def test_parametric_unit_discovery(generic_data, long_datum, unitless_dtype, expected_dtype, nrows): (source)

Check that the correct unit (e.g. month, day, second) is discovered from the data when a user specifies a unitless datetime.

def test_quote_support_default(): (source)

Support for quoted fields is disabled by default.

@pytest.mark.skipif(IS_PYPY and (sys.implementation.version <= (7, 3, 8)), reason='PyPy bug in error formatting')
def test_quotechar_multichar_error(): (source)

Undocumented

@pytest.mark.parametrize('q', ('"', '\'', '`'))
def test_quoted_field(q): (source)

Undocumented

def test_quoted_field_is_not_empty(): (source)

Undocumented

def test_quoted_field_is_not_empty_nonstrict(): (source)

Undocumented

@pytest.mark.parametrize('q', ('"', '\'', '`'))
def test_quoted_field_with_whitepace_delimiter(q): (source)

Undocumented

def test_ragged_usecols(): (source)

Undocumented

def test_read_from_bad_generator(): (source)

Undocumented

def test_read_from_generator(): (source)

Undocumented

def test_read_from_generator_multitype(): (source)

Undocumented

def test_read_huge_row(): (source)

Undocumented

def test_scientific_notation(): (source)

Test that both 'e' and 'E' are parsed correctly.

def test_str_dtype_unit_discovery_with_converter(): (source)

Undocumented

@pytest.mark.parametrize(('given_dtype', 'expected_dtype'), [('S', np.dtype('S5')), ('U', np.dtype('U5'))])
def test_string_no_length_given(given_dtype, expected_dtype): (source)

The given dtype is just 'S' or 'U' with no length. In these cases, the length of the resulting dtype is determined by the longest string found in the file.

@pytest.mark.parametrize('skiprows', [0, 1, 2, 3])
def test_structured_dtype_and_skiprows_no_empty_lines(skiprows, mixed_types_structured): (source)

Undocumented

def test_structured_dtype_offsets(): (source)

Undocumented

def test_structured_dtype_with_multi_shape(): (source)

Undocumented

def test_structured_dtype_with_quotes(): (source)

Undocumented

def test_structured_dtype_with_shape(): (source)

Undocumented

@pytest.mark.parametrize('dtype', (np.typecodes['AllInteger']+'efdFD')+'?')
def test_unicode_whitespace_stripping(dtype): (source)

Undocumented

@pytest.mark.parametrize('dtype', 'FD')
def test_unicode_whitespace_stripping_complex(dtype): (source)

Undocumented

def test_unicode_with_converter(): (source)

Undocumented

@pytest.mark.parametrize('newline', ['\n', '\r', '\r\n'])
def test_universal_newlines_quoted(newline): (source)

Undocumented

def test_unpack_structured(mixed_types_structured): (source)

Undocumented

@pytest.mark.parametrize('data', ('', '\n\n\n', '# 1 2 3\n# 4 5 6\n'))
@pytest.mark.parametrize('ndmin', (0, 1, 2))
@pytest.mark.parametrize('usecols', [None, (1, 2, 3)])
def test_warn_on_no_data(data, ndmin, usecols): (source)

Check that a UserWarning is emitted when no data is read from input.

@pytest.mark.parametrize('skiprows', (2, 3))
def test_warn_on_skipped_data(skiprows): (source)

Undocumented