Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print deprecation warning for usage of Schema from merlin_standard_lib #648

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions merlin_standard_lib/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import json
import os
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypeVar, Union
from warnings import warn

from google.protobuf import json_format, text_format
from google.protobuf.message import Message as ProtoMessage
Expand Down Expand Up @@ -216,6 +217,18 @@ class Schema(_Schema):
"""A collection of column schemas for a dataset."""

feature: List["ColumnSchema"] = betterproto.message_field(1)
_is_first_init = True

def __post_init__(self):
super().__post_init__()
if self._is_first_init:
# TODO: Make description more descriptive. What version are we planning to remove it?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nv-alaiacano @oliverholworthy How should we write this warning? Do we want to commit to a specific release to actually remove it?

warn(
"Schema from `merlin_standard_lib` is deprecated, ",
"use Schema from `merlin.schema` instead.",
DeprecationWarning,
)
self._is_first_init = False

@classmethod
def create(
Expand Down
26 changes: 16 additions & 10 deletions tests/merlin_standard_lib/schema/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# limitations under the License.
#

from warnings import catch_warnings

import pytest

from merlin_standard_lib import categorical_cardinalities
Expand All @@ -37,16 +39,20 @@ def test_column_schema():


def test_schema():
s = schema.Schema(
[
schema.ColumnSchema.create_continuous("con_1"),
schema.ColumnSchema.create_continuous("con_2_int", is_float=False),
schema.ColumnSchema.create_categorical("cat_1", 1000),
schema.ColumnSchema.create_categorical(
"cat_2", 100, value_count=schema.ValueCount(1, 20)
),
]
)
with catch_warnings(record=True) as w:
schema.Schema._is_first_init = True
s = schema.Schema(
[
schema.ColumnSchema.create_continuous("con_1"),
schema.ColumnSchema.create_continuous("con_2_int", is_float=False),
schema.ColumnSchema.create_categorical("cat_1", 1000),
schema.ColumnSchema.create_categorical(
"cat_2", 100, value_count=schema.ValueCount(1, 20)
),
]
)
assert len(w) == 1
assert issubclass(w[0].category, DeprecationWarning)

assert len(s.select_by_type(schema.FeatureType.INT).column_names) == 3
assert len(s.select_by_name(lambda x: x.startswith("con")).column_names) == 2
Expand Down