Skip to content

Conversation

jibarnum
Copy link
Contributor

The easiest way to handle this (w/ the least amount of code changes), was to have store_data convert datetime obs/datetime obs that were converted to strings into seconds since the epoch (before doing anything with the variables "times").

Linked to ticket #77

…cts converted to strings to seconds since the epoch, otherwise, things break
@coveralls
Copy link

coveralls commented Jan 16, 2019

Pull Request Test Coverage Report for Build 110

  • 3 of 7 (42.86%) changed or added relevant lines in 1 file are covered.
  • 277 unchanged lines in 9 files lost coverage.
  • Overall coverage decreased (-0.4%) to 30.519%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pytplot/store_data.py 3 7 42.86%
Files with Coverage Reduction New Missed Lines %
pytplot/init.py 1 66.86%
pytplot/tplot_options.py 3 42.86%
pytplot/tplot.py 6 47.17%
pytplot/cdf_to_tplot.py 18 69.7%
pytplot/HTMLPlotter/TVarFigureAlt.py 24 15.05%
pytplot/HTMLPlotter/TVarFigure1D.py 44 15.24%
pytplot/options.py 51 53.29%
pytplot/tplot_utilities.py 56 28.19%
pytplot/QtPlotter/TVarFigure1D.py 74 50.42%
Totals Coverage Status
Change from base Build 94: -0.4%
Covered Lines: 1399
Relevant Lines: 4584

💛 - Coveralls

# (i.e., times should be in UTC) - convert times to seconds since epoch
if any(isinstance(t, datetime.datetime) for t in times):
for tt, time in enumerate(times):
times[tt] = (time-datetime.datetime(1970, 1, 1)).total_seconds()
Copy link
Member

Choose a reason for hiding this comment

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

While testing this I came across an error that said you can't subtract a datetime object that has a timezone and a datetime object without a timezone. If you give the line "datetime.datetime(1970, 1, 1)" a timezone, then it works.

That said, it looks like there is already a function that converts python datetime objects into seconds since 1970, the "timestamp()" function:

https://docs.python.org/3/library/datetime.html

Though it says it pretty much does exactly the same thing your code has here, but it includes the timezone

(dt - datetime(1970, 1, 1, tzinfo=timezone.utc)).total_seconds()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. Gotta love timezone issues. Fixing this now.

# If given a list of datetime string, convert times to seconds since epoch
elif any(isinstance(t, str) for t in times):
for tt, time in enumerate(times):
times[tt] = [pytplot.tplot_utilities.str_to_int(time)]
Copy link
Member

Choose a reason for hiding this comment

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

And here it looks like you are making a list of single element lists, so times ends up looking like:

[[1], [2], [3], [4]]

instead of

[1, 2, 3, 4]

Copy link
Contributor Author

@jibarnum jibarnum Mar 8, 2019

Choose a reason for hiding this comment

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

Hah, don't ask me why I put times[tt] = a list of the value... I couldn't tell you why. I'll remove the brackets.

@jibarnum jibarnum merged commit fe9b172 into master Mar 8, 2019
@jibarnum jibarnum deleted the julie_store_data_issues branch March 8, 2019 18:04
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