Skip to content

Commit

Permalink
Fix Primitive.value returning None issue (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaels-lyft authored Jul 28, 2020
1 parent b5d8196 commit fe1343c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,46 +39,46 @@ pip install flytekit
If `@spark_task` is to be used, one should install the `spark` plugin.

```bash
pip install flytekit[spark] for Spark 2.4.x
pip install flytekit[spark3] for Spark 3.x
pip install "flytekit[spark]" for Spark 2.4.x
pip install "flytekit[spark3]" for Spark 3.x
```

#### Schema

If `Types.Schema()` is to be used for computations involving large dataframes, one should install the `schema` extension.

```bash
pip install flytekit[schema]
pip install "flytekit[schema]"
```

#### Sidecar

If `@sidecar_task` is to be used, one should install the `sidecar` plugin.

```bash
pip install flytekit[sidecar]
pip install "flytekit[sidecar]"
```

### Pytorch

If `@pytorch_task` is to be used, one should install the `pytorch` plugin.

```bash
pip install flytekit[pytorch]
pip install "flytekit[pytorch]"
```

### Full Installation

To install all or multiple available plugins, one can specify them individually:

```bash
pip install flytekit[sidecar,spark,schema]
pip install "flytekit[sidecar,spark,schema]"
```

Or install them with the `all` directive. `all` defaults to Spark 2.4.x currently.

```bash
pip install flytekit[all]
pip install "flytekit[all]"
```

## Testing
Expand All @@ -92,7 +92,7 @@ Flytekit is Python 2.7+ compatible, so when feasible, it is recommended to test
virtualenv ~/.virtualenvs/flytekit
source ~/.virtualenvs/flytekit/bin/activate
python -m pip install -r requirements.txt
python -m pip install -U .[all]
python -m pip install -U ".[all]"
```

#### Execute
Expand Down
2 changes: 1 addition & 1 deletion flytekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

import flytekit.plugins

__version__ = "0.10.10"
__version__ = "0.10.11"
4 changes: 3 additions & 1 deletion flytekit/models/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def value(self):
This returns whichever field is set.
:rtype: T
"""
return self.integer or self.float_value or self.string_value or self.boolean or self.datetime or self.duration
for value in [self.integer, self.float_value, self.string_value, self.boolean, self.datetime, self.duration]:
if value is not None:
return value

def to_flyte_idl(self):
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/flytekit/unit/models/test_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def test_integer_primitive():
assert obj2 != literals.Primitive(float_value=1.0)
assert obj2 != literals.Primitive(string_value='abc')

obj3 = literals.Primitive(integer=0)
assert obj3.value == 0

with pytest.raises(Exception):
literals.Primitive(integer=1.0).to_flyte_idl()

Expand Down Expand Up @@ -91,6 +94,9 @@ def test_boolean_primitive():
assert obj2 != literals.Primitive(float_value=1.0)
assert obj2 != literals.Primitive(string_value='abc')

obj3 = literals.Primitive(boolean=False)
assert obj3.value is False

with pytest.raises(Exception):
literals.Primitive(boolean=datetime.now()).to_flyte_idl()

Expand Down Expand Up @@ -201,6 +207,9 @@ def test_float_primitive():
assert obj2 != literals.Primitive(float_value=0.0)
assert obj2 != literals.Primitive(string_value='abc')

obj3 = literals.Primitive(float_value=0.0)
assert obj3.value == 0.0

with pytest.raises(Exception):
literals.Primitive(float_value='abc').to_flyte_idl()

Expand Down Expand Up @@ -237,6 +246,9 @@ def test_string_primitive():
assert obj2 != literals.Primitive(float_value=0.0)
assert obj2 != literals.Primitive(string_value='bca')

obj3 = literals.Primitive(string_value="")
assert obj3.value == ""

with pytest.raises(Exception):
literals.Primitive(string_value=1.0).to_flyte_idl()

Expand Down

0 comments on commit fe1343c

Please sign in to comment.