Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/safeds/data/tabular/containers/_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from safeds._validation import _check_bounds, _check_columns_exist, _ClosedBound, _normalize_and_check_file_path
from safeds._validation._check_columns_dont_exist import _check_columns_dont_exist
from safeds.data.tabular.plotting import TablePlotter
from safeds.data.tabular.typing._polars_data_type import _PolarsDataType
from safeds.data.tabular.typing._polars_schema import _PolarsSchema
from safeds.exceptions import (
ColumnLengthMismatchError,
Expand Down Expand Up @@ -390,13 +389,7 @@ def column_count(self) -> int:
>>> table.column_count
2
"""
import polars as pl

try:
return self._lazy_frame.width
except (pl.NoDataError, pl.PolarsPanicError):
# Can happen for some operations on empty tables (e.g. https://github.com/pola-rs/polars/issues/16202)
return 0
return len(self.column_names)

@property
def row_count(self) -> int:
Expand Down Expand Up @@ -612,8 +605,7 @@ def get_column_type(self, name: str) -> DataType:
>>> table.get_column_type("a")
Int64
"""
_check_columns_exist(self, name)
return _PolarsDataType(self._lazy_frame.schema[name])
return self.schema.get_column_type(name)

def has_column(self, name: str) -> bool:
"""
Expand All @@ -636,7 +628,7 @@ def has_column(self, name: str) -> bool:
>>> table.has_column("a")
True
"""
return name in self.column_names
return self.schema.has_column(name)

def remove_columns(
self,
Expand Down
2 changes: 1 addition & 1 deletion src/safeds/data/tabular/typing/_polars_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def column_names(self) -> list[str]:
# ------------------------------------------------------------------------------------------------------------------

def get_column_type(self, name: str) -> DataType:
_check_columns_exist(self, [name])
_check_columns_exist(self, name)

return _PolarsDataType(self._schema[name])

Expand Down