khiops.core.internals.io
Submodule of khiops.core.internals
Classes to handle Khiops specific I/O
| CLASS | DESCRIPTION |
|---|---|
KhiopsJSONObject |
Represents the contents of a Khiops JSON file |
KhiopsOutputWriter |
Output writer with additional services to handle Khiops special encodings |
| FUNCTION | DESCRIPTION |
|---|---|
encode_file_path |
Encodes a file path |
flexible_json_load |
Loads flexibly a JSON file |
Classes
KhiopsJSONObject(json_data=None)
Represents the contents of a Khiops JSON file
| PARAMETER | DESCRIPTION |
|---|---|
json_data
|
Python dictionary representing the data of a Khiops JSON file. If None or empty it returns an empty object.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
KhiopsJSONError
|
If the JSON data is invalid. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
tool |
Name of the Khiops tool that generated the file.
TYPE:
|
version |
Version of the Khiops tool that generated the file.
TYPE:
|
khiops_encoding |
Custom encoding used by Khiops in the file. Valid values:
-
TYPE:
|
sub_tool |
Identifies the tool that originated the JSON file. Used by tools of the Khiops family such as PataText or Enneade.
TYPE:
|
json_key_sort_spec |
Dictionary that specifies the order of the keys in the Khiops JSON report. Its values are None, except when they are dictionaries themselves. Note This is a class attribute that can be set in subclasses, to specify a key order when serializing the report in a JSON file, via the write_khiops_json_file method.
TYPE:
|
json_data |
Python dictionary extracted from the Khiops JSON report file. Deprecated will be removed in Khiops 12.
TYPE:
|
See class docstring
| METHOD | DESCRIPTION |
|---|---|
create_output_file_writer |
Creates an output file with the proper encoding settings |
to_dict |
Serialize object instance to the Khiops JSON format |
write_khiops_json_file |
Write the JSON data of the object to a Khiops JSON file |
Methods:
create_output_file_writer(stream)
Creates an output file with the proper encoding settings
| PARAMETER | DESCRIPTION |
|---|---|
stream
|
An output stream object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
KhiopsOutputWriter
|
An output file object. |
to_dict()
Serialize object instance to the Khiops JSON format
write_khiops_json_file(json_file_path, _ensure_ascii=False)
Write the JSON data of the object to a Khiops JSON file
The JSON keys are sorted according to the
KhiopsJSONObject.json_key_sort_spec class attribute, if set.
Otherwise, the JSON keys are not sorted.
| PARAMETER | DESCRIPTION |
|---|---|
json_file_path
|
Path to the Khiops JSON file.
TYPE:
|
_ensure_ascii
|
If True, then non-ASCII characters in the report are escaped. Otherwise, they are dumped as-is.
TYPE:
|
KhiopsOutputWriter(stream, force_ansi=False, ansi_unicode_chars=None)
Output writer with additional services to handle Khiops special encodings
| PARAMETER | DESCRIPTION |
|---|---|
stream
|
A writable output stream. Special text transformations in buffers inheriting from io.TextIOBase are ignored.
TYPE:
|
force_ansi
|
All output written will be transformed back ANSI characters in that range that were recoded to UTF-8.
TYPE:
|
ansi_unicode_chars
|
A list of UTF-8 characters with equivalents in the ANSI 128-256 range which will
be encoded back to ANSI when writing with
TYPE:
|
Functions:
encode_file_path(file_path)
Encodes a file path
This is custom path encoding for Khiops scenarios that is platform dependent. The encoding is done only if file_path is of type str.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
The path of a file. |
| RETURNS | DESCRIPTION |
|---|---|
bytes
|
If |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If |