Skip to content

Instantly share code, notes, and snippets.

@kerel-fs
Last active October 20, 2020 07:50
Show Gist options
  • Save kerel-fs/01b3730cd39222ca531921f0459aa493 to your computer and use it in GitHub Desktop.
Save kerel-fs/01b3730cd39222ca531921f0459aa493 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "AssertionError",
"evalue": "\nNot equal to tolerance rtol=1e-07, atol=0\n\nMismatched elements: 1 / 1 (100%)\nMax absolute difference: 719163.\nMax relative difference: 38.77011406\n x: array(737712.416667)\n y: array(18549.416667)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-d431215d0067>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;31m# Compare astropy.Time.plot_date with matplotlib.dates.date2num result\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0massert_quantity_allclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt_astropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mplot_date\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdate2num\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mt_datetime\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m~/.virtualenvs/2020-10-14/lib/python3.8/site-packages/astropy/tests/helper.py\u001b[0m in \u001b[0;36massert_quantity_allclose\u001b[0;34m(actual, desired, rtol, atol, **kwargs)\u001b[0m\n\u001b[1;32m 480\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 481\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mastropy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munits\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquantity\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0m_unquantify_allclose_arguments\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 482\u001b[0;31m np.testing.assert_allclose(*_unquantify_allclose_arguments(\n\u001b[0m\u001b[1;32m 483\u001b[0m actual, desired, rtol, atol), **kwargs)\n",
" \u001b[0;31m[... skipping hidden 2 frame]\u001b[0m\n",
"\u001b[0;31mAssertionError\u001b[0m: \nNot equal to tolerance rtol=1e-07, atol=0\n\nMismatched elements: 1 / 1 (100%)\nMax absolute difference: 719163.\nMax relative difference: 38.77011406\n x: array(737712.416667)\n y: array(18549.416667)"
]
}
],
"source": [
"from datetime import datetime\n",
"from matplotlib.dates import num2date, date2num\n",
"from astropy.time import Time\n",
"from astropy.tests.helper import assert_quantity_allclose\n",
"\n",
"# ISO 8601-formatted timestamp\n",
"t_str = '2020-10-14T10:00:00'\n",
"\n",
"# Create astropy.time.Time object from string\n",
"t_astropy = Time(t_str)\n",
"\n",
"# Create datetime.datetime object from string\n",
"t_datetime = datetime.fromisoformat(t_str)\n",
"\n",
"# Compare astropy.Time.plot_date with matplotlib.dates.date2num result\n",
"assert_quantity_allclose(t_astropy.plot_date, date2num(t_datetime))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "2020-10-14",
"language": "python",
"name": "2020-10-14"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
git+https://github.com/astropy/astropy@04e218ce85ae42e90d1f7e15840cbb61d44646e4#egg=astropy
matplotlib
numpy
pytest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment