Container

csv

rxsci.container.csv.create_line_parser(dtype, none_values=[], separator=',', ignore_error=False, schema_name='x')

creates a parser for csv lines

Parameters
  • dtype – A list of (name, type) tuples.

  • none_values – [Optional] Values to consider as None values

  • separator – [Optional] Token used to separate each columns

  • ignore_error – [Optional] when set to True, any line that does not match the provided number of columns raise an error an stop the parsing. When set to False, error lines are skipped.

Returns

A Parsing function, that can parse text lines as specified in the parameters.

rxsci.container.csv.dump(header=True, separator=',', newline='\n')

dumps an observable to csv.

The source observable must emit one csv row per item The source must be an Observable.

Parameters
  • header – [Optional] indicates whether a header line must be added.

  • separator – [Optional] Token used to separate each columns.

  • newline – [Optional] Character(s) used for end of line.

Returns

An observable string items, where each item is a csv line.

rxsci.container.csv.dump_to_file(filename, header=True, separator=',', newline='\n', encoding=None, transport_params=None)

dumps each item to a csv file.

The source must be an Observable.

Parameters
  • filename – Path of the file to read

  • header – [Optional] indicates whether a header line must be added.

  • separator – [Optional] Token used to separate each columns.

  • newline – [Optional] Character(s) used for end of line.

  • [Optional] Encoding used to parse the text content (encoding) –

  • transport_params – [Optional] When smart-open is used, then this parameter is used to provide additional configuration information

Returns

An empty observable that completes on success when the source observable completes or completes on error if there is an error while writing the csv file.

rxsci.container.csv.load(parse_line, skip=0)

Loads a csv observable.

The source observable must emit one csv row per item The source must be an Observable.

Parameters
  • parse_line – A line parser, e.g. created with create_line_parser

  • skip – number of items to skip before parsing

Returns

An observable of namedtuple items, where each key is a csv column

rxsci.container.csv.load_from_file(filename, parse_line, skip=1, encoding=None, transport_params=None)

Loads a csv file.

This factory loads the provided file and returns its content as an observable emitting one item per line.

Parameters
  • filename – Path of the file to read

  • parse_line – A line parser, e.g. created with create_line_parser

  • skip – [Optional] Number of lines to skip before parsing

  • [Optional] Encoding used to parse the text content (encoding) –

  • transport_params – [Optional] When smart-open is used, then this parameter is used to provide additional configuration information

Returns

An observable of namedtuple items, where each key is a csv column