Skip to content

Commit

Permalink
docs: fix example output
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-reimann committed May 19, 2024
1 parent 6c4a360 commit 645e856
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 32 deletions.
7 changes: 6 additions & 1 deletion src/resources/from_json_file.json
Original file line number Diff line number Diff line change
@@ -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] }
]
}
6 changes: 0 additions & 6 deletions src/resources/from_json_file_2.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/resources/to_json_file.json
Original file line number Diff line number Diff line change
@@ -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]}]}
6 changes: 0 additions & 6 deletions src/resources/to_json_file_2.json

This file was deleted.

158 changes: 142 additions & 16 deletions src/safeds/data/tabular/containers/_string_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class StringCell(ABC):
>>> 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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 |
+---------+
"""

# ------------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| --- | --- |
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 645e856

Please sign in to comment.