Skip to content

Store LatLong columns as object dtype containing tuples - #414

Merged
tamargrey merged 27 commits into
mainfrom
tuple-latlong
Dec 7, 2020
Merged

tamargrey merged 27 commits into
mainfrom
tuple-latlong

Conversation

@tamargrey

@tamargrey tamargrey commented Nov 24, 2020 •

Copy link
Copy Markdown
Contributor

Comment thread woodwork/datacolumn.py
self._series = dd.from_pandas(formatted_series, npartitions=self._series.npartitions)
elif ks and isinstance(self._series, ks.Series):
formatted_series = self._series.to_pandas().apply(_reformat_to_latlong, use_list=True)
self._series = ks.from_pandas(formatted_series)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ideally, we could just use apply on the dd and ks dataframes, but with Dask, we don't know the format of the data in the column (the "meta" like how it gets used in featuretools here. ), and with Koalas, there was an issue with User Defined Functions (UDFs).

There might be a better way of doing this conversion to the standard format, so I'm open to any suggestions here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the dask apply to use apply directly on the Dask series (I wasn't thinking before, but of course we do know the desired format since the whole point of this is to get the standard tuple([str, str]) formatting.)

Still haven't found a better way to do the koalas apply, though.

Comment thread woodwork/tests/datatable/test_datatable.py

error = re.escape("LatLongs must either be a tuple, a list, or a string representation of a tuple. (1,2) does not fit the criteria.")
with pytest.raises(ValueError, match=error):
_reformat_to_latlong("'(1,2)'")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know how you'd get this case as an input, but the error message here is misleading, and I'm wondering if we might want to handle this case.

Comment thread woodwork/utils.py
Comment thread woodwork/tests/datatable/test_serialization.py
@codecov

codecov Bot commented Nov 25, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #414 (e4360b9) into main (e44cec6) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              main      #414    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           31        31            
  Lines         4065      4221   +156     
==========================================
+ Hits          4065      4221   +156     
Impacted Files Coverage Δ
woodwork/datacolumn.py 100.00% <100.00%> (ø)
woodwork/datatable.py 100.00% <100.00%> (ø)
woodwork/logical_types.py 100.00% <100.00%> (ø)
woodwork/serialize.py 100.00% <100.00%> (ø)
woodwork/tests/conftest.py 100.00% <100.00%> (ø)
woodwork/tests/datacolumn/conftest.py 100.00% <100.00%> (ø)
woodwork/tests/datacolumn/test_data_column.py 100.00% <100.00%> (ø)
woodwork/tests/datatable/test_datatable.py 100.00% <100.00%> (ø)
woodwork/tests/datatable/test_serialization.py 100.00% <100.00%> (ø)
woodwork/tests/test_utils.py 100.00% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e44cec6...af8e3b5. Read the comment docs.

@tamargrey
tamargrey requested a review from gsheni November 30, 2020 14:23
Comment thread docs/source/release_notes.rst Outdated
Comment thread woodwork/datacolumn.py Outdated
Comment thread woodwork/logical_types.py Outdated
Comment thread woodwork/logical_types.py Outdated
Comment thread woodwork/tests/conftest.py Outdated
Comment thread woodwork/tests/datatable/test_datatable.py Outdated
Comment thread woodwork/tests/test_utils.py Outdated
Comment thread woodwork/utils.py
Comment thread woodwork/datatable.py
Comment thread woodwork/tests/conftest.py Outdated
Comment thread woodwork/tests/conftest.py Outdated
Comment thread woodwork/utils.py Outdated
Comment thread woodwork/tests/datatable/test_serialization.py Outdated
Comment thread woodwork/tests/datatable/test_serialization.py Outdated
Comment thread woodwork/tests/test_utils.py Outdated
Comment thread woodwork/tests/datatable/test_serialization.py
@tamargrey
tamargrey force-pushed the tuple-latlong branch 2 times, most recently from dd58591 to ae67d56 Compare December 2, 2020 20:33

@thehomebrewnerd thehomebrewnerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is looking pretty good - one subject for discussion. In describe for LatLongs I think we are only including np.nan in our nan_count results, but we would not consider (np.nan, 43) or (np.nan, np.nan) as having missing values. I'm not sure what the right approach is here, but it sort of feels like (np.nan, np.nan) should be counted as missing. Not as sure about (np.nan, 43).

@tamargrey

Copy link
Copy Markdown
Contributor Author

I'm not sure what the right approach is here, but it sort of feels like (np.nan, np.nan) should be counted as missing. Not as sure about (np.nan, 43).

My initial thought is that an interesting way to do that would be to have latlong columns be three columns in the describe df: one for latlong, one for lat, and one for long. And for the separated out lat and long values we could do a wider array of calculations since they're numeric. Then again, is it useful to know the average latitude or the standard dev?

For simplicity, though. I think conflating np.nan with (np.nan, np.nan) in our nan count works. But if, say, 80% of latitudes couldn't be calculated, it's misleading to say that 80% of the data is null, since, in theory, you could still get useful information about the longitude, which is why having the separate lat and long columns could be useful.

@gsheni

gsheni commented Dec 3, 2020 •

Copy link
Copy Markdown
Contributor

@tamargrey I think it's very dataset dependent if average latitude is useful or not. So the best we can do from a Woodwork perspective is to provide the information. So I like your idea of having 3 columns for describing a LatLong. We can do this in a follow up MR. No need to worry about that now.

  • For the nan count, we can keep it simple for now, and see how its used. If I had to guess, I would say it going to depend on the user, and what they are looking for.

@gsheni gsheni left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@thehomebrewnerd thehomebrewnerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me!

@tamargrey
tamargrey merged commit 0748222 into main Dec 7, 2020
@gsheni gsheni mentioned this pull request Dec 14, 2020
@gsheni
gsheni deleted the tuple-latlong branch December 22, 2020 21:37
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.

Change LatLong from string to object dtype for faster access

3 participants