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

CLN: datetimelike arrays: isort, small reorg #23587

Merged
merged 21 commits into from
Nov 12, 2018

Conversation

jbrockmendel
Copy link
Member

Big diff, few real changes.

Implement __repr__ for DTA/TDA. Shared with PeriodArray implementation. Added truncation so we don't print all N elements. Adds tests for all three subclasses. Creates dedicated test files for test_datetimes and test_timedeltas

Some PeriodArray methods got shuffled into weird places, so this puts them back.
Collects wrapping-properties in DatetimeIndex.
isort on indexes/datetimelike, datetimes, timedeltas

@pep8speaks
Copy link

Hello @jbrockmendel! Thanks for submitting the PR.

@codecov
Copy link

codecov bot commented Nov 9, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@592fd64). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #23587   +/-   ##
=========================================
  Coverage          ?   92.24%           
=========================================
  Files             ?      161           
  Lines             ?    51316           
  Branches          ?        0           
=========================================
  Hits              ?    47337           
  Misses            ?     3979           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.63% <100%> (?)
#single 42.29% <79.59%> (?)
Impacted Files Coverage Δ
pandas/core/arrays/timedeltas.py 95.08% <ø> (ø)
pandas/core/arrays/datetimes.py 98.44% <ø> (ø)
pandas/core/indexes/period.py 93.04% <ø> (ø)
pandas/core/arrays/datetimelike.py 95.92% <100%> (ø)
pandas/core/indexes/datetimelike.py 98.01% <100%> (ø)
pandas/core/indexes/timedeltas.py 89.26% <100%> (ø)
pandas/core/arrays/period.py 98.49% <100%> (ø)
pandas/core/indexes/datetimes.py 96.12% <100%> (ø)

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 592fd64...c7211f7. Read the comment docs.

pandas/core/arrays/datetimelike.py Outdated Show resolved Hide resolved
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

LGTM at a glance. What's the motivation for aliasing DatetimeArrayMixin to DatetimeArray, rather than doing the rename all at once?

pandas/core/arrays/timedeltas.py Show resolved Hide resolved
@jbrockmendel
Copy link
Member Author

What's the motivation for aliasing DatetimeArrayMixin to DatetimeArray, rather than doing the rename all at once?

In several branches where I have tried doing it all-at-once the diffs become difficult for even me to read. Getting this out of the way early saves some trouble.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Some minor comments

pandas/core/arrays/datetimelike.py Outdated Show resolved Hide resolved
@@ -286,10 +282,6 @@ def _ndarray_values(self):
# Ordinals
return self._data

@property
def asi8(self):
return self._data
Copy link
Member

Choose a reason for hiding this comment

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

but for datetimes the _data is not integer?

Copy link
Member Author

Choose a reason for hiding this comment

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

The inherited implementation returns self._data.view('i8'). The view is redundant for PeriodArray, but still correct

microsecond = wrap_field_accessor(DatetimeArrayMixin.microsecond)
nanosecond = wrap_field_accessor(DatetimeArrayMixin.nanosecond)
weekofyear = wrap_field_accessor(DatetimeArrayMixin.weekofyear)
# override DatetimeLikeArrayMixin.__repr__
Copy link
Member

Choose a reason for hiding this comment

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

can you add a "TODO remove" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, but FWIW that's the point of collecting things in this section

@@ -256,8 +256,15 @@ def _simple_new(cls, values, name=None, freq=None, **kwargs):
result._reset_identity()
return result

# ------------------------------------------------------------------------
# Wrapping PeriodArray
Copy link
Member

Choose a reason for hiding this comment

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

What is this section for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Collecting things that will soon be changed by the inheritance/composition in one place. For PeriodIndex its a pretty small set



class TestDatetimeArray(object):
def test_repr(self):
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to put this in a class? Or do like in PeriodArray tests?

Copy link
Member

Choose a reason for hiding this comment

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

It would be more idiomatic to use functions, unless we need the class org for a particular reason. The same goes for all of the other add tests.

@jbrockmendel
Copy link
Member Author

Are we OK with merging this and then shortly thereafter getting rid of the __repr__ here and replace it with #23601? Or should I remove repr and tests from this PR?

@TomAugspurger
Copy link
Contributor

I'm going to revert the repr changes if that's OK. We'll need to change them eventually, when the name changes from ArrayMixin to just Array, and since they aren't inheriting from ExtensionArray yet the formatting on #23601 won't quite work..

@TomAugspurger
Copy link
Contributor

Converted the new array repr tests to xfails. We'll need to be a bit careful with those once we DatetimeArrayMixin inherits from DatetimeArray. I may not have gotten the future formatting 100% correct.

@jbrockmendel
Copy link
Member Author

Sounds good, thanks.

@jbrockmendel
Copy link
Member Author

Fixed I sort that broke travis, hopefully got all of them

pandas/core/indexes/datetimes.py Show resolved Hide resolved
pandas/tests/arrays/test_datetimelike.py Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
@gfyoung gfyoung added Datetime Datetime data dtype Output-Formatting __repr__ of pandas objects, to_string Refactor Internal refactoring of code labels Nov 11, 2018
@jbrockmendel
Copy link
Member Author

Travis fail is Hypothesis

pandas/core/indexes/datetimes.py Show resolved Hide resolved
pandas/tests/arrays/test_datetimes.py Outdated Show resolved Hide resolved
pandas/tests/arrays/test_timedeltas.py Outdated Show resolved Hide resolved
@jbrockmendel
Copy link
Member Author

I see you have added [_timezone] [...] what is the point of _timezones when _tz already does this?

I didn't add this, has existed for a while. No idea what the original reasoning was. Maybe just an alias?

@jreback
Copy link
Contributor

jreback commented Nov 11, 2018

@jbrockmendel #23587 (comment)

ok. can you create an issue about seeing what that is about. it seems pretty confusing (though its actually a nice name).

@jreback jreback added this to the 0.24.0 milestone Nov 11, 2018
@jreback
Copy link
Contributor

jreback commented Nov 11, 2018

lgtm. ping on green (circle seems to have failed <:)

# Wrapping PeriodArray

# override DatetimeLikeArrayMixin.__repr__
__repr__ = Index.__repr__
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed now I think? (now the repr changes are reversed?)

@jorisvandenbossche jorisvandenbossche changed the title REF/ENH: __repr__ for DTA/TDA, tests, isort CLN: datetimelike arrays: isort, small reorg Nov 12, 2018
@jorisvandenbossche jorisvandenbossche merged commit 3592a46 into pandas-dev:master Nov 12, 2018
@jorisvandenbossche
Copy link
Member

Thanks @jbrockmendel !

@jbrockmendel jbrockmendel deleted the dlike_ea3 branch November 12, 2018 14:43
thoo added a commit to thoo/pandas that referenced this pull request Nov 12, 2018
* upstream/master:
  BUG: Don't over-optimize memory with jagged CSV (pandas-dev#23527)
  DEPR: Deprecate usecols as int in read_excel (pandas-dev#23635)
  More helpful Stata string length error. (pandas-dev#23629)
  BUG: astype fill_value for SparseArray.astype (pandas-dev#23547)
  CLN: datetimelike arrays: isort, small reorg (pandas-dev#23587)
  CI: Check in the CI that assert_raises_regex is not being used (pandas-dev#23627)
  CLN:Remove unused **kwargs from user facing methods (pandas-dev#23249)
  DOC: Enhancing pivot / reshape docs (pandas-dev#21038)
  TST: Fix xfailing DataFrame arithmetic tests by transposing (pandas-dev#23620)
thoo added a commit to thoo/pandas that referenced this pull request Nov 12, 2018
…fixed

* upstream/master:
  DOC: avoid SparseArray.take error (pandas-dev#23637)
  CLN: remove incorrect usages of com.AbstractMethodError (pandas-dev#23625)
  DOC: Adding validation of the section order in docstrings (pandas-dev#23607)
  BUG: Don't over-optimize memory with jagged CSV (pandas-dev#23527)
  DEPR: Deprecate usecols as int in read_excel (pandas-dev#23635)
  More helpful Stata string length error. (pandas-dev#23629)
  BUG: astype fill_value for SparseArray.astype (pandas-dev#23547)
  CLN: datetimelike arrays: isort, small reorg (pandas-dev#23587)
  CI: Check in the CI that assert_raises_regex is not being used (pandas-dev#23627)
  CLN:Remove unused **kwargs from user facing methods (pandas-dev#23249)
JustinZhengBC pushed a commit to JustinZhengBC/pandas that referenced this pull request Nov 14, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Output-Formatting __repr__ of pandas objects, to_string Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants