Skip to content

Python TileUDT and rf_type.Tile improvements - #146

Merged
vpipkt merged 3 commits into
locationtech:developfrom
s22s:feature/more_udt_tests
Jun 18, 2019
Merged

vpipkt merged 3 commits into
locationtech:developfrom
s22s:feature/more_udt_tests

Conversation

@vpipkt

@vpipkt vpipkt commented Jun 12, 2019

Copy link
Copy Markdown
Member

No description provided.

Signed-off-by: Jason T. Brown <jason@astraea.earth>
@vpipkt
vpipkt requested a review from metasim June 12, 2019 16:15
def my_udf(t):
import numpy as np
a = np.log1p(t.cells)
return Tile(a, CellType.from_numpy_dtype(a.dtype))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This kind of pattern is showing up more and more. See also our Tile.add, Tile.sub etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My hope is that we can make udfs a true path of last resort... what can we do to get closer to feature complete with columnar functions?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed. i think the familiar model here is that one could iterate over values in a numpy array but it is uncommon in practice because the built in functions are more convenient and known to be faster. I am glad the user gets some rope. But we also have to make this point clear in docs.

@vpipkt vpipkt changed the title Add unit tests using python TileUDT in UDF's. WIP: Add unit tests using python TileUDT in UDF's. Jun 12, 2019
@vpipkt

vpipkt commented Jun 12, 2019

Copy link
Copy Markdown
Member Author

Marked WIP going to add a few more goodies.

…ality correctly handles no_data; add __matmul__ operator

Signed-off-by: Jason T. Brown <jason@astraea.earth>
@vpipkt vpipkt changed the title WIP: Add unit tests using python TileUDT in UDF's. Add unit tests using python TileUDT in UDF's. Jun 12, 2019
@vpipkt vpipkt changed the title Add unit tests using python TileUDT in UDF's. Python TileUDT and rf_type.Tile improvements Jun 12, 2019
def __eq__(self, other):
if type(other) is type(self):
return self.cell_type == other.cell_type and np.array_equal(self.cells, other.cells)
return self.cell_type == other.cell_type and np.ma.allequal(self.cells, other.cells)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

turns out np.ma.allequal behaves the same as np.array_equal for regular (not masked) ndarray's.

Signed-off-by: Jason T. Brown <jason@astraea.earth>
)

df_result = df.select(
(rf_dimensions(df.tile).cols.cast('int') * rf_dimensions(df.tile).rows.cast('int') -

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need an rf_size function?

@udf(TileUDT())
def my_udf(t):
import numpy as np
return Tile(np.log1p(t.cells))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

win!

@vpipkt
vpipkt merged commit d29634a into locationtech:develop Jun 18, 2019
@vpipkt
vpipkt deleted the feature/more_udt_tests branch June 24, 2019 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants