Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented to_list to Index/MultiIndex #1948

Merged
merged 5 commits into from
Dec 5, 2020

Conversation

itholic
Copy link
Contributor

@itholic itholic commented Dec 3, 2020

Added to_list - tolist as an alias - to the Index and MultiIndex.

This implementation idea is basically inspired from Series.to_list.

>>> idx = ks.Index([1, 2, 3, 4, 5])
>>> idx.to_list()
[1, 2, 3, 4, 5]

>>> tuples = [(1, 'red'), (1, 'blue'), (2, 'red'), (2, 'green')]
>>> midx = ks.MultiIndex.from_tuples(tuples)
>>> midx.to_list()
[(1, 'red'), (1, 'blue'), (2, 'red'), (2, 'green')]

@itholic
Copy link
Contributor Author

itholic commented Dec 3, 2020

FYI: This implementation idea is basically inspired from Series.to_list.

def to_list(self) -> List:
"""
Return a list of the values.
These are each a scalar type, which is a Python scalar
(for str, int, float) or a pandas scalar
(for Timestamp/Timedelta/Interval/Period)
.. note:: This method should only be used if the resulting list is expected
to be small, as all the data is loaded into the driver's memory.
"""
# pandas<0.24 doesn't support `to_list()` as an alias for `tolist()`
if LooseVersion(pd.__version__) < LooseVersion("0.24"):
return self._to_internal_pandas().tolist()
else:
return self._to_internal_pandas().to_list()
tolist = to_list

@codecov-io
Copy link

Codecov Report

Merging #1948 (d2df72f) into master (e598f44) will decrease coverage by 3.30%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1948      +/-   ##
==========================================
- Coverage   94.50%   91.19%   -3.31%     
==========================================
  Files          45       49       +4     
  Lines       10682    10712      +30     
==========================================
- Hits        10095     9769     -326     
- Misses        587      943     +356     
Impacted Files Coverage Δ
databricks/koalas/missing/indexes.py 100.00% <ø> (ø)
databricks/koalas/indexes.py 96.94% <100.00%> (+0.09%) ⬆️
databricks/koalas/usage_logging/__init__.py 25.66% <0.00%> (-66.65%) ⬇️
databricks/koalas/usage_logging/usage_logger.py 47.82% <0.00%> (-52.18%) ⬇️
databricks/koalas/__init__.py 68.75% <0.00%> (-21.88%) ⬇️
databricks/conftest.py 89.83% <0.00%> (-10.17%) ⬇️
databricks/koalas/spark/functions.py 88.88% <0.00%> (-7.41%) ⬇️
databricks/koalas/accessors.py 86.43% <0.00%> (-7.04%) ⬇️
databricks/koalas/namespace.py 78.17% <0.00%> (-6.07%) ⬇️
databricks/koalas/generic.py 87.89% <0.00%> (-5.03%) ⬇️
... and 24 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 e598f44...d2df72f. Read the comment docs.

@@ -102,6 +102,7 @@ Conversion

Index.astype
Index.item
Index.to_list
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we exclude "tolist" on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because pandas also exclude tolist in their docs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, thanks!

@xinrong-meng xinrong-meng self-requested a review December 4, 2020 18:59
@itholic
Copy link
Contributor Author

itholic commented Dec 5, 2020

I'll merge this for now. Let's address #1948 (comment)
cc @ueshin

@itholic itholic merged commit 7e06e43 into databricks:master Dec 5, 2020
@xinrong-meng
Copy link
Contributor

ref #1929

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.

5 participants