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

Implement DatetimeIndex.indexer_at_time() #2109

Merged
merged 4 commits into from
Mar 19, 2021

Conversation

xinrong-meng
Copy link
Contributor

@xinrong-meng xinrong-meng commented Mar 18, 2021

>>> kidx = ks.date_range("2000-01-01", periods=3, freq="T")
>>> kidx
DatetimeIndex(['2000-01-01 00:00:00', '2000-01-01 00:01:00',
               '2000-01-01 00:02:00'],
              dtype='datetime64[ns]', freq=None)

>>> kidx.indexer_at_time("00:00")
Int64Index([0], dtype='int64')

>>> kidx.indexer_at_time("00:01")
Int64Index([1], dtype='int64')

@@ -634,6 +636,49 @@ def strftime(self, date_format: str) -> Index:
"""
return Index(self.to_series().dt.strftime(date_format))

def indexer_at_time(self, time: Union[datetime.time, str], asof: bool = False) -> Index:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

asof is not implemented in pandas yet, so there is not docstring for it.
https://github.com/pandas-dev/pandas/blob/v1.2.3/pandas/core/indexes/datetimes.py#L828-L865

Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we check it before we call apply_batch; otherwise the error will be messy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea!

@codecov-io
Copy link

Codecov Report

Merging #2109 (1a12359) into master (e38ac6d) will decrease coverage by 5.31%.
The diff coverage is 94.73%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2109      +/-   ##
==========================================
- Coverage   95.21%   89.90%   -5.32%     
==========================================
  Files          60       60              
  Lines       13460    13339     -121     
==========================================
- Hits        12816    11992     -824     
- Misses        644     1347     +703     
Impacted Files Coverage Δ
databricks/koalas/missing/indexes.py 100.00% <ø> (ø)
databricks/koalas/indexes/datetimes.py 96.32% <92.30%> (-2.08%) ⬇️
databricks/koalas/tests/indexes/test_datetime.py 97.43% <100.00%> (-2.57%) ⬇️
databricks/koalas/plot/plotly.py 15.78% <0.00%> (-81.06%) ⬇️
...bricks/koalas/tests/plot/test_frame_plot_plotly.py 23.33% <0.00%> (-76.67%) ⬇️
...ricks/koalas/tests/plot/test_series_plot_plotly.py 26.92% <0.00%> (-71.26%) ⬇️
databricks/koalas/usage_logging/__init__.py 28.20% <0.00%> (-64.36%) ⬇️
databricks/koalas/usage_logging/usage_logger.py 47.82% <0.00%> (-52.18%) ⬇️
databricks/koalas/typedef/typehints.py 66.66% <0.00%> (-27.90%) ⬇️
databricks/koalas/__init__.py 77.63% <0.00%> (-14.48%) ⬇️
... and 30 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 e38ac6d...1a12359. Read the comment docs.

Copy link
Collaborator

@ueshin ueshin left a comment

Choose a reason for hiding this comment

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

Otherwise, LGTM.
Could you also fix the conflicts?

@@ -634,6 +636,49 @@ def strftime(self, date_format: str) -> Index:
"""
return Index(self.to_series().dt.strftime(date_format))

def indexer_at_time(self, time: Union[datetime.time, str], asof: bool = False) -> Index:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shall we check it before we call apply_batch; otherwise the error will be messy.

Examples
--------
>>> kidx = ks.date_range("2000-01-01", periods=3, freq="T")
>>> kidx # doctest: +NORMALIZE_WHITESPACE
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: 2 spaces between kidx and # doctest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@ueshin
Copy link
Collaborator

ueshin commented Mar 19, 2021

Thanks! merging.

@ueshin ueshin merged commit 48c311b into databricks:master Mar 19, 2021
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.

3 participants