Skip to content

Commit

Permalink
refactor(config): remove kw_only from dataclass fields
Browse files Browse the repository at this point in the history
Removed `kw_only` from dataclass fields in `ProcessorConfig` and
`PlotterConfig` classes. This change simplifies the initialization of
these classes and improves code readability.
  • Loading branch information
psmyth94 committed Nov 18, 2024
1 parent 728e878 commit 89a2081
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 40 deletions.
49 changes: 19 additions & 30 deletions src/biofit/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@
import pyarrow as pa
from biocore import DataHandler, get_data_format
from biocore.utils.import_util import (
is_polars_available,
is_ray_available,
is_biosets_available,
is_datasets_available,
is_polars_available,
is_ray_available,
)
from biocore.utils.inspect import get_kwargs, get_required_args
from biocore.utils.naming import camelcase_to_snakecase
from biocore.utils.py_util import (
is_bioset,
is_dataset,
is_dataset_dict,
is_iterable_dataset,
)
from sklearn.utils.validation import (
NotFittedError,
)
Expand All @@ -60,13 +66,6 @@
from biofit.utils.file_utils import expand_path, is_remote_url
from biofit.utils.fingerprint import Hasher, is_caching_enabled
from biofit.utils.py_util import iflatmap_unordered
from biocore.utils.py_util import (
is_bioset,
is_dataset,
is_dataset_dict,
is_iterable_dataset,
)

from biofit.utils.table_util import string_to_arrow

if TYPE_CHECKING:
Expand Down Expand Up @@ -955,24 +954,16 @@ class ProcessorConfig(BaseConfig):
data for transformation (e.g. selecting the same columns, etc.).
"""

output_format: str = field(default=None, kw_only=True, init=True, repr=False)
input_columns: SelectedColumnTypes = field(
default=None, kw_only=True, init=True, repr=False
)
unused_columns: SelectedColumnTypes = field(
default=None, kw_only=True, init=True, repr=False
)
keep_unused_columns: bool = field(default=True, kw_only=True, init=True, repr=False)
raise_if_missing: bool = field(default=True, kw_only=True, init=True, repr=False)
enable_caching: bool = field(default=True, kw_only=True, init=True, repr=False)
cache_output: bool = field(default=True, kw_only=True, init=True, repr=False)
load_from_cache_file: bool = field(
default=True, kw_only=True, init=True, repr=False
)
cache_dir: str = field(default=None, kw_only=True, init=True, repr=False)
version: str = field(
default=version.__version__, kw_only=True, init=True, repr=True
)
output_format: str = field(default=None, init=True, repr=False)
input_columns: SelectedColumnTypes = field(default=None, init=True, repr=False)
unused_columns: SelectedColumnTypes = field(default=None, init=True, repr=False)
keep_unused_columns: bool = field(default=True, init=True, repr=False)
raise_if_missing: bool = field(default=True, init=True, repr=False)
enable_caching: bool = field(default=True, init=True, repr=False)
cache_output: bool = field(default=True, init=True, repr=False)
load_from_cache_file: bool = field(default=True, init=True, repr=False)
cache_dir: str = field(default=None, init=True, repr=False)
version: str = field(default=version.__version__, init=True, repr=True)

_fit_process_desc: str = field(
default="Fitting the processor to the input data", init=False, repr=False
Expand All @@ -994,9 +985,7 @@ class ProcessorConfig(BaseConfig):
default=None, init=False, repr=False
)

_input_columns: SelectedColumnTypes = field(
default=None, kw_only=True, init=False, repr=False
)
_input_columns: SelectedColumnTypes = field(default=None, init=False, repr=False)
features_out_suffix: str = field(default=None, init=False, repr=False)
features_out_prefix: str = field(default=None, init=False, repr=False)
processor_type: str = field(default="", init=False, repr=False)
Expand Down
18 changes: 8 additions & 10 deletions src/biofit/visualization/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from biocore import DataHandler
from biocore.utils.import_util import is_ipywidgets_available, is_matplotlib_available
from biocore.utils.naming import camelcase_to_snakecase
from biocore.utils.py_util import is_dataset_dict

from biofit.integration.R.r_caller import RCaller
from biofit.processing import (
Expand All @@ -25,7 +26,6 @@
logging,
move_temp_file,
)
from biocore.utils.py_util import is_dataset_dict
from biofit.visualization.plotting_utils import (
display_image_carousel,
is_in_notebook,
Expand Down Expand Up @@ -57,15 +57,13 @@ def _processor_info_from_fingerprint(fingerprint: str):

@dataclass
class PlotterConfig(BaseConfig):
path: str = field(default=None, kw_only=True, init=True, repr=True)
device: str = field(default="pdf", kw_only=True, init=True, repr=False)
fingerprint: str = field(default=None, kw_only=True, init=True, repr=False)
unused_columns: SelectedColumnTypes = field(
default=None, kw_only=True, init=True, repr=False
)
raise_if_missing: bool = field(default=True, kw_only=True, init=True, repr=False)
cache_dir: str = field(default=None, kw_only=True, init=True, repr=False)
version: str = field(default="0.0.0", kw_only=True, init=True, repr=False)
path: str = field(default=None, init=True, repr=True)
device: str = field(default="pdf", init=True, repr=False)
fingerprint: str = field(default=None, init=True, repr=False)
unused_columns: SelectedColumnTypes = field(default=None, init=True, repr=False)
raise_if_missing: bool = field(default=True, init=True, repr=False)
cache_dir: str = field(default=None, init=True, repr=False)
version: str = field(default="0.0.0", init=True, repr=False)

_input_columns: SelectedColumnTypes = field(default=None, init=False, repr=False)
_compare: bool = field(default=False, init=False, repr=False)
Expand Down

0 comments on commit 89a2081

Please sign in to comment.