Skip to content

Commit f384bf4

Browse files
nkovela1copybara-github
authored andcommitted
Add a warning to all FeatureColumn functions.
This change adds a deprecation warning to the FeatureColumn API that encourages migration to Keras preprocessing layers instead (with a link) and also links the user to the TF2 migration guide. PiperOrigin-RevId: 483785240
1 parent 00b7460 commit f384bf4

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

tools/tensorflow_docs/api_generator/doc_controls.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@ def is_deprecated(obj) -> bool:
3535

3636
def inheritable_header(text: str):
3737

38-
def _wrapped(cls):
39-
setattr(cls, _INHERITABLE_HEADER, text)
40-
return cls
38+
def _wrapped(obj):
39+
setattr(obj, _INHERITABLE_HEADER, text)
40+
return obj
4141

4242
return _wrapped
4343

4444

45-
def get_inheritable_header(cls) -> Optional[str]:
46-
return getattr(cls, _INHERITABLE_HEADER, None)
45+
def get_inheritable_header(obj) -> Optional[str]:
46+
return getattr(obj, _INHERITABLE_HEADER, None)
47+
48+
49+
header = inheritable_header
50+
get_header = get_inheritable_header
4751

4852

4953
_NO_SEARCH_HINTS = "_tf_docs_no_search_hints"
5054

5155

56+
5257
def hide_from_search(obj: T) -> T:
5358
"""Marks an object so metadata search hints will not be included on it's page.
5459

tools/tensorflow_docs/api_generator/pretty_docs/function_page.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
# ==============================================================================
15-
from typing import Any
15+
import textwrap
16+
from typing import Any, Optional
1617

18+
from tensorflow_docs.api_generator import doc_controls
1719
from tensorflow_docs.api_generator import parser
1820
from tensorflow_docs.api_generator import signature as signature_lib
1921
from tensorflow_docs.api_generator.pretty_docs import base_page
@@ -86,5 +88,12 @@ def decorators(self):
8688
def add_decorator(self, dec):
8789
self._decorators.append(dec)
8890

91+
@property
92+
def header(self) -> Optional[str]:
93+
header = doc_controls.get_header(self.py_object)
94+
if header is not None:
95+
header = textwrap.dedent(header)
96+
return header
97+
8998
def get_metadata_html(self):
9099
return parser.Metadata(self.full_name).build_html()

tools/tensorflow_docs/api_generator/pretty_docs/templates/function.jinja

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
{% extends "templates/page.jinja" %}
22

3+
{#----------------------------------------------------------------------------#}
4+
5+
{% block metadata %}
6+
{{ builder.top_source_link() }}
7+
8+
{{ page_info.doc.brief }}
9+
10+
{% if page_info.header %}
11+
12+
13+
{{ page_info.header -}}
14+
{% endif %}
15+
16+
{{ builder.build_collapsable_aliases() -}}
17+
{% endblock metadata %}
18+
19+
{#----------------------------------------------------------------------------#}
20+
321
{% block body %}
422
{% if page_info.signature %}
523
{{ builder.build_signature() }}

0 commit comments

Comments
 (0)