From e35c755d5d5305c8f1c73ea4edd3ed1eff636563 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sun, 19 May 2024 16:56:08 +0200 Subject: [PATCH] docs: fix example output --- src/resources/from_json_file.json | 7 +- src/resources/from_json_file_2.json | 6 - src/resources/to_json_file.json | 2 +- src/resources/to_json_file_2.json | 6 - .../data/tabular/containers/_string_cell.py | 160 ++++++++++++++++-- src/safeds/data/tabular/containers/_table.py | 4 +- 6 files changed, 152 insertions(+), 33 deletions(-) delete mode 100644 src/resources/from_json_file_2.json delete mode 100644 src/resources/to_json_file_2.json diff --git a/src/resources/from_json_file.json b/src/resources/from_json_file.json index 5965ef149..5cd814134 100644 --- a/src/resources/from_json_file.json +++ b/src/resources/from_json_file.json @@ -1 +1,6 @@ -{ "a": { "0": 1, "1": 2, "2": 3 }, "b": { "0": 4, "1": 5, "2": 6 } } +{ + "columns": [ + { "name": "a", "datatype": "Int64", "bit_settings": "", "values": [1, 2, 3] }, + { "name": "b", "datatype": "Int64", "bit_settings": "", "values": [4, 5, 6] } + ] +} diff --git a/src/resources/from_json_file_2.json b/src/resources/from_json_file_2.json deleted file mode 100644 index 5cd814134..000000000 --- a/src/resources/from_json_file_2.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "columns": [ - { "name": "a", "datatype": "Int64", "bit_settings": "", "values": [1, 2, 3] }, - { "name": "b", "datatype": "Int64", "bit_settings": "", "values": [4, 5, 6] } - ] -} diff --git a/src/resources/to_json_file.json b/src/resources/to_json_file.json index 5965ef149..29d04896f 100644 --- a/src/resources/to_json_file.json +++ b/src/resources/to_json_file.json @@ -1 +1 @@ -{ "a": { "0": 1, "1": 2, "2": 3 }, "b": { "0": 4, "1": 5, "2": 6 } } +{"columns":[{"name":"a","datatype":"Int64","bit_settings":"","values":[1,2,3]},{"name":"b","datatype":"Int64","bit_settings":"","values":[4,5,6]}]} \ No newline at end of file diff --git a/src/resources/to_json_file_2.json b/src/resources/to_json_file_2.json deleted file mode 100644 index 5cd814134..000000000 --- a/src/resources/to_json_file_2.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "columns": [ - { "name": "a", "datatype": "Int64", "bit_settings": "", "values": [1, 2, 3] }, - { "name": "b", "datatype": "Int64", "bit_settings": "", "values": [4, 5, 6] } - ] -} diff --git a/src/safeds/data/tabular/containers/_string_cell.py b/src/safeds/data/tabular/containers/_string_cell.py index 49fc8c613..e47a41444 100644 --- a/src/safeds/data/tabular/containers/_string_cell.py +++ b/src/safeds/data/tabular/containers/_string_cell.py @@ -13,14 +13,22 @@ class StringCell(ABC): """ Namespace for operations on strings. - This class cannot be instantiated directly. It can only be accessed using the `string` attribute of a cell. + This class cannot be instantiated directly. It can only be accessed using the `str` attribute of a cell. Examples -------- >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["ab", "bc", "cd"]) >>> column.transform(lambda cell: cell.str.to_uppercase()) - ["AB", "BC", "CD"] + +---------+ + | example | + | --- | + | str | + +=========+ + | AB | + | BC | + | CD | + +---------+ """ @abstractmethod @@ -89,7 +97,15 @@ def index_of(self, substring: str) -> Cell[int | None]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["ab", "bc", "cd"]) >>> column.transform(lambda cell: cell.str.index_of("b")) - [1, 0, None] + +---------+ + | example | + | --- | + | u32 | + +=========+ + | 1 | + | 0 | + | null | + +---------+ """ @abstractmethod @@ -113,7 +129,15 @@ def length(self, *, optimize_for_ascii: bool = False) -> Cell[int]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["", "a", "abc"]) >>> column.transform(lambda cell: cell.str.length()) - [0, 1, 3] + +---------+ + | example | + | --- | + | u32 | + +=========+ + | 0 | + | 1 | + | 3 | + +---------+ """ @abstractmethod @@ -138,7 +162,15 @@ def replace(self, old: str, new: str) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["ab", "bc", "cd"]) >>> column.transform(lambda cell: cell.str.replace("b", "z")) - ["az", "zc", "cd"] + +---------+ + | example | + | --- | + | str | + +=========+ + | az | + | zc | + | cd | + +---------+ """ @abstractmethod @@ -192,7 +224,15 @@ def substring(self, start: int = 0, length: int | None = None) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["abc", "def", "ghi"]) >>> column.transform(lambda cell: cell.str.substring(1, 2)) - ["bc", "ef", "hi"] + +---------+ + | example | + | --- | + | str | + +=========+ + | bc | + | ef | + | hi | + +---------+ """ @abstractmethod @@ -210,7 +250,15 @@ def to_date(self) -> Cell[datetime.date | None]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["2021-01-01", "2021-02-01", "abc"]) >>> column.transform(lambda cell: cell.str.to_date()) - ["2021-01-01", "2021-02-01", None] + +------------+ + | example | + | --- | + | date | + +============+ + | 2021-01-01 | + | 2021-02-01 | + | null | + +------------+ """ @abstractmethod @@ -226,9 +274,17 @@ def to_datetime(self) -> Cell[datetime.datetime | None]: Examples -------- >>> from safeds.data.tabular.containers import Column - >>> column = Column("example", ["2021-01-01T00:00:00", "2021-02-01T00:00:00", "abc"]) + >>> column = Column("example", ["2021-01-01T00:00:00z", "2021-02-01T00:00:00z", "abc"]) >>> column.transform(lambda cell: cell.str.to_datetime()) - ["2021-01-01 00:00:00", "2021-02-01 00:00:00", None] + +-------------------------+ + | example | + | --- | + | datetime[μs, UTC] | + +=========================+ + | 2021-01-01 00:00:00 UTC | + | 2021-02-01 00:00:00 UTC | + | null | + +-------------------------+ """ @abstractmethod @@ -246,7 +302,16 @@ def to_float(self) -> Cell[float | None]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["1", "3.4", "5.6", "abc"]) >>> column.transform(lambda cell: cell.str.to_float()) - [1.0, 3.4, 5.6, None] + +---------+ + | example | + | --- | + | f64 | + +=========+ + | 1.00000 | + | 3.40000 | + | 5.60000 | + | null | + +---------+ """ @abstractmethod @@ -269,11 +334,29 @@ def to_int(self, *, base: int = 10) -> Cell[int | None]: >>> from safeds.data.tabular.containers import Column >>> column1 = Column("example", ["1", "2", "3", "abc"]) >>> column1.transform(lambda cell: cell.str.to_int()) - [1, 2, 3, None] + +---------+ + | example | + | --- | + | i64 | + +=========+ + | 1 | + | 2 | + | 3 | + | null | + +---------+ >>> column2 = Column("example", ["1", "10", "11", "abc"]) >>> column2.transform(lambda cell: cell.str.to_int(base=2)) - [1, 2, 3, None] + +---------+ + | example | + | --- | + | i64 | + +=========+ + | 1 | + | 2 | + | 3 | + | null | + +---------+ """ @abstractmethod @@ -291,7 +374,15 @@ def to_lowercase(self) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["AB", "BC", "CD"]) >>> column.transform(lambda cell: cell.str.to_lowercase()) - ["ab", "bc", "cd"] + +---------+ + | example | + | --- | + | str | + +=========+ + | ab | + | bc | + | cd | + +---------+ """ @abstractmethod @@ -309,7 +400,15 @@ def to_uppercase(self) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["ab", "bc", "cd"]) >>> column.transform(lambda cell: cell.str.to_uppercase()) - ["AB", "BC", "CD"] + +---------+ + | example | + | --- | + | str | + +=========+ + | AB | + | BC | + | CD | + +---------+ """ @abstractmethod @@ -327,7 +426,16 @@ def trim(self) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["", " abc", "abc ", " abc "]) >>> column.transform(lambda cell: cell.str.trim()) - ["", "abc", "abc", "abc"] + +---------+ + | example | + | --- | + | str | + +=========+ + | | + | abc | + | abc | + | abc | + +---------+ """ @abstractmethod @@ -345,7 +453,16 @@ def trim_end(self) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["", " abc", "abc ", " abc "]) >>> column.transform(lambda cell: cell.str.trim_end()) - ["", " abc", "abc", " abc"] + +---------+ + | example | + | --- | + | str | + +=========+ + | | + | abc | + | abc | + | abc | + +---------+ """ @abstractmethod @@ -363,7 +480,16 @@ def trim_start(self) -> Cell[str]: >>> from safeds.data.tabular.containers import Column >>> column = Column("example", ["", " abc", "abc ", " abc "]) >>> column.transform(lambda cell: cell.str.trim_start()) - ["", "abc", "abc ", "abc "] + +---------+ + | example | + | --- | + | str | + +=========+ + | | + | abc | + | abc | + | abc | + +---------+ """ # ------------------------------------------------------------------------------------------------------------------ diff --git a/src/safeds/data/tabular/containers/_table.py b/src/safeds/data/tabular/containers/_table.py index 476791915..80f7971de 100644 --- a/src/safeds/data/tabular/containers/_table.py +++ b/src/safeds/data/tabular/containers/_table.py @@ -225,7 +225,7 @@ def from_json_file(path: str | Path) -> Table: Examples -------- >>> from safeds.data.tabular.containers import Table - >>> Table.from_json_file("./src/resources/from_json_file_2.json") + >>> Table.from_json_file("./src/resources/from_json_file.json") +-----+-----+ | a | b | | --- | --- | @@ -1883,7 +1883,7 @@ def to_json_file( -------- >>> from safeds.data.tabular.containers import Table >>> table = Table({"a": [1, 2, 3], "b": [4, 5, 6]}) - >>> table.to_json_file("./src/resources/to_json_file_2.json") + >>> table.to_json_file("./src/resources/to_json_file.json") """ path = _normalize_and_check_file_path(path, ".json", [".json"]) path.parent.mkdir(parents=True, exist_ok=True)