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
4 changes: 4 additions & 0 deletions dataprofiler/profilers/json_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def get_profiler_class(class_name: str) -> type[BaseProfiler]:
:param class_name: name of BaseProfiler subclass retrieved by
calling type(instance).__name__
:type class_name: str representing name of class

:raises: ValueError if the profiler class does not exist

:return: subclass of BaseProfiler object
"""
profiler_class: type[BaseProfiler] | None = _profilers.get(class_name)
Expand Down Expand Up @@ -201,6 +204,7 @@ def load_option(serialized_json: dict, options: dict | None = None) -> BaseOptio
:type options: Dict | None
:return: subclass of BaseOption that has been deserialized from
JSON

"""
option_cls: type[BaseOption] = get_option_class(serialized_json["class"])
return option_cls.load_from_dict(serialized_json["data"], options)
Expand Down
8 changes: 8 additions & 0 deletions dataprofiler/profilers/json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@ def default(self, to_serialize):

:param to_serialize: an object to be serialized
:type to_serialize: a BaseColumnProfile object

:raises: NotImplementedError

:return: a datatype serializble by json.JSONEncoder
"""
if isinstance(to_serialize, profile_builder.UnstructuredProfiler):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

raise NotImplementedError(
"UnstructuredProfiler serialization not supported."
)

if isinstance(
to_serialize,
(
Expand Down
18 changes: 18 additions & 0 deletions dataprofiler/profilers/profile_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,24 @@ def report(self, report_options: dict = None) -> dict:
report["data_stats"] = self._profile.report(remove_disabled_flag)
return _prepare_report(report, output_format, omit_keys)

@classmethod
def load_from_dict(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes

Copy link
Contributor

@JGSweets JGSweets Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep this is good

cls,
data,
options: dict | None = None,
):
"""
Parse attribute from json dictionary into self.

:param data: dictionary with attributes and values.
:type data: dict[string, Any]
:param options: options for loading column profiler params from dictionary
:type options: Dict | None

:raises: NotImplementedError
"""
raise NotImplementedError("UnstructuredProfiler deserialization not supported.")

@utils.method_timeit(name="clean_and_base_stats")
def _clean_data_and_get_base_stats(
self, data: pd.Series, sample_size: int, min_true_samples: int = None
Expand Down
19 changes: 19 additions & 0 deletions dataprofiler/tests/profilers/test_profile_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,25 @@ def test_min_true_samples(self, *mocks):
profile = dp.UnstructuredProfiler(empty_df, min_true_samples=10)
self.assertEqual(10, profile._min_true_samples)

def test_encode(self, *mocks):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beauty

profiler = UnstructuredProfiler(None)
with self.assertRaisesRegex(
NotImplementedError, "UnstructuredProfiler serialization not supported."
):
json.dumps(profiler, cls=ProfileEncoder)

def test_decode(self, *mocks):
with self.assertRaisesRegex(
ValueError, "Invalid profiler class UnstructuredProfiler failed to load."
):
load_profiler({"class": "UnstructuredProfiler", "data": {}})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might also want a load_from_dict raise error that we can remove once it is functional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


def test_load_from_dict(self, *mocks):
with self.assertRaisesRegex(
NotImplementedError, "UnstructuredProfiler deserialization not supported."
):
UnstructuredProfiler.load_from_dict({}, None)


class TestUnstructuredProfilerWData(unittest.TestCase):
@classmethod
Expand Down