Skip to content

implement constructors for TimedeltaArray, DatetimeArray #21803

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

Merged
merged 3 commits into from
Jul 8, 2018

Conversation

jbrockmendel
Copy link
Member

Implements AttributesMixin since this is a pattern we might want to formalize.

The _simple_new that this implements for TimedeltaArray and DatetimeArray are pretty close to the "full" versions in the Index classes. The __new__ methods though are very much stripped down for the now.

With these in place we get to move tz_convert and tz_localize. Could do a bunch more if I wasn't too much of a wuss to do it all in one go.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

minor comments

if is_int:
val = getitem(key)
return self._box_func(val)
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need the else here

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the existing __getitem__ moved verbatim. Can de-indent in the next pass.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks!

return result

def __new__(cls, values, freq=None, tz=None):
if (freq is not None and not isinstance(freq, DateOffset) and
Copy link
Contributor

Choose a reason for hiding this comment

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

this condition could actually be handled to by to_offset (future PR) (except for the not-None part)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yah, I anticipate most of the existing constructors will be moved from the Index subclasses to the Array subclasses; for now I just need something that works for the cases that are called internally.

@jreback jreback added Datetime Datetime data dtype Timedelta Timedelta data type Period Period data type ExtensionArray Extending pandas with custom dtypes or arrays. labels Jul 7, 2018
@jreback jreback added this to the 0.24.0 milestone Jul 7, 2018
@jbrockmendel
Copy link
Member Author

Just updated to de-conflict changes to tz_convert/tz_localize docstrings.

@codecov
Copy link

codecov bot commented Jul 8, 2018

Codecov Report

Merging #21803 into master will decrease coverage by 0.04%.
The diff coverage is 79.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #21803      +/-   ##
==========================================
- Coverage   91.95%    91.9%   -0.05%     
==========================================
  Files         160      160              
  Lines       49858    49902      +44     
==========================================
+ Hits        45845    45864      +19     
- Misses       4013     4038      +25
Flag Coverage Δ
#multiple 90.29% <79.1%> (-0.05%) ⬇️
#single 42.1% <64.17%> (+0.01%) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/period.py 94.4% <ø> (-0.04%) ⬇️
pandas/core/arrays/period.py 85.71% <100%> (-0.65%) ⬇️
pandas/core/indexes/datetimelike.py 97.01% <100%> (+0.15%) ⬆️
pandas/core/indexes/timedeltas.py 91.06% <100%> (+0.05%) ⬆️
pandas/core/indexes/datetimes.py 95.13% <100%> (-0.1%) ⬇️
pandas/core/arrays/timedelta.py 87.65% <64%> (-10.63%) ⬇️
pandas/core/arrays/datetimes.py 93.62% <70.45%> (-6.38%) ⬇️
pandas/core/arrays/datetimelike.py 93.71% <90%> (-1.98%) ⬇️

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 5cb5880...192c920. Read the comment docs.

@jreback jreback merged commit 90cffc5 into pandas-dev:master Jul 8, 2018
@jreback
Copy link
Contributor

jreback commented Jul 8, 2018

thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the dtarrays24 branch July 11, 2018 20:23
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype ExtensionArray Extending pandas with custom dtypes or arrays. Period Period data type Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants