liferoad commented on code in PR #26290: URL: https://github.com/apache/beam/pull/26290#discussion_r1227278078
########## sdks/python/apache_beam/transforms/timestamped_value_type_test.py: ########## @@ -0,0 +1,118 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import unittest +from typing import Any +from typing import Dict +from typing import List + +import apache_beam as beam +from apache_beam.transforms.window import TimestampedValue +from apache_beam.typehints.decorators import TypeCheckError + + +def ConvertToTimestampedValue(plant: Dict[str, Any]) -> TimestampedValue[str]: + return TimestampedValue[str](plant["name"], plant["season"]) + + +def ConvertToTimestampedValue_1(plant: Dict[str, Any]) -> TimestampedValue: + return TimestampedValue(plant["name"], plant["season"]) + + +def ConvertToTimestampedValue_2( + plant: Dict[str, Any]) -> TimestampedValue[List[str]]: + return TimestampedValue[List[str]](plant["name"], plant["season"]) + + +class TypeCheckTimestampedValueTestCase(unittest.TestCase): + def setUp(self): + self.opts = beam.options.pipeline_options.PipelineOptions( + runtime_type_check=True) + self.data = [ + { + "name": "Strawberry", "season": 1585699200 + }, # April, 2020 + ] + self.data_1 = [ + { + "name": 1234, "season": 1585699200 + }, # April, 2020 + ] + self.data_2 = [ + { + "name": ["abc", "cde"], "season": 1585699200 + }, # April, 2020 + ] + self.data_3 = [ + { + "name": [123, "cde"], "season": 1585699200 + }, # April, 2020 + ] + + def test_pcoll_hints(self): + for fn in (ConvertToTimestampedValue, ConvertToTimestampedValue_1): + pc = beam.Map(fn) + ht = pc.default_type_hints() + assert len(ht) == 3 + # assert ht.output_types[0][0] == TimestampedValue[str] + assert ht.output_types[0][0] Review Comment: We only transfer the typing module to the beam type now per: https://github.com/apache/beam/blob/master/sdks/python/apache_beam/typehints/native_type_compatibility.py#L261 I am not sure we want to treat TimestampedValue differently. The current design is to do the runtime checks with the given type for TimestampedValue. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
