Skip to content

BUG: Fix TimeFormatter behavior with fractional seconds #18552

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

Closed
wants to merge 11 commits into from

Conversation

nmartensen
Copy link
Contributor

@nmartensen nmartensen commented Nov 28, 2017

@codecov
Copy link

codecov bot commented Nov 28, 2017

Codecov Report

Merging #18552 into master will decrease coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18552      +/-   ##
==========================================
- Coverage   91.63%   91.57%   -0.07%     
==========================================
  Files         154      153       -1     
  Lines       51422    51366      -56     
==========================================
- Hits        47123    47039      -84     
- Misses       4299     4327      +28
Flag Coverage Δ
#multiple 89.44% <100%> (-0.05%) ⬇️
#single 40.73% <0%> (-0.21%) ⬇️
Impacted Files Coverage Δ
pandas/plotting/_converter.py 65.22% <100%> (-1.3%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/util/testing.py 82.34% <0%> (-0.58%) ⬇️
pandas/core/categorical.py 95.64% <0%> (-0.15%) ⬇️
pandas/core/indexes/interval.py 93.8% <0%> (-0.04%) ⬇️
pandas/tseries/frequencies.py 94.02% <0%> (-0.03%) ⬇️
pandas/core/sparse/frame.py 94.78% <0%> (-0.03%) ⬇️
pandas/core/indexes/datetimes.py 95.7% <0%> (-0.02%) ⬇️
pandas/core/indexes/base.py 96.43% <0%> (-0.01%) ⬇️
... and 6 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 0303d0d...c1ace38. Read the comment docs.

@jreback
Copy link
Contributor

jreback commented Dec 2, 2017

@TomAugspurger

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.

Ping on green.

@@ -107,19 +107,22 @@ def __init__(self, locs):
self.locs = locs

def __call__(self, x, pos=0):
fmt = '%H:%M:%S'
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a doc-string here

Copy link
Contributor

Choose a reason for hiding this comment

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

cam you add a Parameters sections

Copy link
Contributor

Choose a reason for hiding this comment

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

and a Returns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

# time2num(datetime.time.min)
rs = self.tc(0)
xp = '00:00'
assert rs == xp
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a blank line before the comments

@@ -112,7 +112,24 @@ def test_conversion_outofbounds_datetime(self):
assert rs == xp

def test_time_formatter(self):
self.tc(90000)
Copy link
Contributor

Choose a reason for hiding this comment

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

add the issue number here as a comment

xp = '23:59:59.999999'
assert rs == xp
# some other times
rs = self.tc(90000)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need a test from the original issue, which check that the plot works

@jreback jreback added the Visualization plotting label Dec 2, 2017
@nmartensen nmartensen force-pushed the time_formatter branch 3 times, most recently from 878687a to 200528b Compare December 7, 2017 21:52
@nmartensen
Copy link
Contributor Author

Do you know why GH still says "changes requested"? I believe all comments are addressed.

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.

can you post a plot from before and after here

@@ -125,6 +125,7 @@ Plotting
^^^^^^^^

- Bug in ``DataFrame.plot()`` and ``Series.plot()`` with :class:`DatetimeIndex` where a figure generated by them is not pickleable in Python 3 (:issue:`18439`)
- Bug in :class:`TimeFormatter` when trying to display fractional seconds (:issue:`18478`).
Copy link
Contributor

Choose a reason for hiding this comment

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

move to 0.22.0

Copy link
Contributor

Choose a reason for hiding this comment

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

actually this is ok

@nmartensen
Copy link
Contributor Author

Example code:

ax = pandas.DataFrame({'A': 1}, index=[pydt.time(11, 2, 59, 899502), pydt.time(11, 3, 0, 123456)]).plot()
for l in ax.xaxis.get_majorticklabels():
    l.set_rotation(45)
    l.set_horizontalalignment('right')

Output before:
eleven_before

Output after:
eleven_after

@jreback
Copy link
Contributor

jreback commented Dec 9, 2017

is it standard to only show the most resolved, IOW, 11:03 rather than 11:03:00, IOW we always want to show HH:MM:SS (but not show millis unless needed).

@nmartensen
Copy link
Contributor Author

My original motivation to change the TimeFormatter was to get rid of the :SS since I was always plotting full days. But if you prefer, we can drop that commit.

I didn't discover the sub-second breakage from a real usecase, but while reading the code to figure out where I'd need to change it for the above.

@jreback
Copy link
Contributor

jreback commented Dec 9, 2017

My original motivation to change the TimeFormatter was to get rid of the :SS since I was always plotting full days. But if you prefer, we can drop that commit.

do we do a similar thing for fractional datetimes? cc @TomAugspurger @jorisvandenbossche @tacaswell

@nmartensen
Copy link
Contributor Author

The ideal way would probably be to not show the seconds if they are zero for each tick position, and show them if they are non-zero for at least one tick position. But I don't know how to implement that.

@nmartensen
Copy link
Contributor Author

For comparison some plots illustrating tick labels with datetimes. Code:

fig, axes = plt.subplots(nrows=6, ncols=1, figsize=(6, 10))
for i, ut in enumerate(['H', 'min', 'S', 'ms', 'us', 'N']):
    dti = pandas.date_range('11:02:59.889502', periods=2, freq='200'+ut)
    pandas.DataFrame({'A': 1}, index=dti).plot(ax=axes[i])
    axes[i].set_title('delta t = 200'+ut, position=(0.5, 0.6))
    axes[i].text(0.5, 0.1, str(dti.max()-dti.min()), transform=axes[i].transAxes, ha='center')

plt.tight_layout()

Resulting output:
datetime_ticklabels

@jreback jreback modified the milestone: 0.22.0 Dec 21, 2017
@jreback jreback added this to the 0.23.0 milestone Dec 21, 2017
@jreback
Copy link
Contributor

jreback commented Dec 21, 2017

thanks @nmartensen

@jreback jreback closed this in 75b97a7 Dec 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TimeFormatter broken for sub-second resolution
3 participants