-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
py35+ compatibility, modularize, update Julia 1.0
prereq
- Loading branch information
Showing
12 changed files
with
128 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
language: python | ||
sudo: required | ||
dist: xenial | ||
group: travis_latest | ||
|
||
git: | ||
depth: 3 | ||
quiet: true | ||
|
||
python: | ||
- 3.5 | ||
- 3.6 | ||
- 3.7 | ||
- pypy3 | ||
|
||
os: | ||
- linux | ||
|
||
install: pip install -e .[tests] | ||
install: | ||
- pip install -e .[tests] | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* && $TRAVIS_OS_NAME == linux ]]; then pip install -e .[cov]; fi | ||
|
||
script: | ||
- pytest -rsv | ||
- flake8 | ||
- mypy . --ignore-missing-imports | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* && $TRAVIS_OS_NAME == linux ]]; then flake8; fi | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* && $TRAVIS_OS_NAME == linux ]]; then mypy . --ignore-missing-imports; fi | ||
|
||
after_success: | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then | ||
pytest --cov; | ||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* && $TRAVIS_OS_NAME == linux ]]; then | ||
pytest --cov --cov-config=setup.cfg; | ||
coveralls; | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
include LICENSE | ||
recursive-include tests *.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
#= | ||
command-line utility to convert date to day of year | ||
=# | ||
using Base.Dates | ||
using Dates | ||
using ArgParse | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Tuple, Any | ||
import numpy as np | ||
import datetime | ||
|
||
|
||
def find_nearest(x, x0) -> Tuple[int, Any]: | ||
""" | ||
This find_nearest function does NOT assume sorted input | ||
inputs: | ||
x: array (float, int, datetime, h5py.Dataset) within which to search for x0 | ||
x0: singleton or array of values to search for in x | ||
outputs: | ||
idx: index of flattened x nearest to x0 (i.e. works with higher than 1-D arrays also) | ||
xidx: x[idx] | ||
Observe how bisect.bisect() gives the incorrect result! | ||
idea based on: | ||
http://stackoverflow.com/questions/2566412/find-nearest-value-in-numpy-array | ||
""" | ||
x = np.asanyarray(x) # for indexing upon return | ||
x0 = np.atleast_1d(x0) | ||
# %% | ||
if x.size == 0 or x0.size == 0: | ||
raise ValueError('empty input(s)') | ||
|
||
if x0.ndim not in (0, 1): | ||
raise ValueError('2-D x0 not handled yet') | ||
# %% | ||
ind = np.empty_like(x0, dtype=int) | ||
|
||
# NOTE: not trapping IndexError (all-nan) becaues returning None can surprise with slice indexing | ||
for i, xi in enumerate(x0): | ||
if xi is not None and (isinstance(xi, (datetime.datetime, datetime.date, np.datetime64)) or np.isfinite(xi)): | ||
ind[i] = np.nanargmin(abs(x-xi)) | ||
else: | ||
raise ValueError('x0 must NOT be None or NaN to avoid surprising None return value') | ||
|
||
return ind.squeeze()[()], x[ind].squeeze()[()] # [()] to pop scalar from 0d array while being OK with ndim>0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Union | ||
import numpy as np | ||
import datetime | ||
from pytz import UTC | ||
from dateutil.parser import parse | ||
|
||
|
||
def forceutc(t: Union[str, datetime.datetime, datetime.date, np.datetime64]) -> Union[datetime.datetime, datetime.date]: | ||
""" | ||
Add UTC to datetime-naive and convert to UTC for datetime aware | ||
input: python datetime (naive, utc, non-utc) or Numpy datetime64 #FIXME add Pandas and AstroPy time classes | ||
output: utc datetime | ||
""" | ||
# need to passthrough None for simpler external logic. | ||
# %% polymorph to datetime | ||
if isinstance(t, str): | ||
t = parse(t) | ||
elif isinstance(t, np.datetime64): | ||
t = t.astype(datetime.datetime) | ||
elif isinstance(t, datetime.datetime): | ||
pass | ||
elif isinstance(t, datetime.date): | ||
return t | ||
elif isinstance(t, (np.ndarray, list, tuple)): | ||
return np.asarray([forceutc(T) for T in t]) | ||
else: | ||
raise TypeError('datetime only input') | ||
# %% enforce UTC on datetime | ||
if t.tzinfo is None: # datetime-naive | ||
t = t.replace(tzinfo=UTC) | ||
else: # datetime-aware | ||
t = t.astimezone(UTC) # changes timezone, preserving absolute time. E.g. noon EST = 5PM UTC | ||
|
||
return t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
[metadata] | ||
name = sciencedates | ||
version = 1.4.3 | ||
version = 1.4.4 | ||
author = Michael Hirsch, Ph.D. | ||
author_email = [email protected] | ||
url = https://github.com/scivision/sciencedates | ||
description = Date conversions used in the sciences. | ||
keywords = | ||
|
@@ -11,17 +12,19 @@ classifiers = | |
Development Status :: 5 - Production/Stable | ||
Environment :: Console | ||
Intended Audience :: Science/Research | ||
License :: OSI Approved :: MIT License | ||
Operating System :: OS Independent | ||
Programming Language :: Python :: 3.5 | ||
Programming Language :: Python :: 3.6 | ||
Programming Language :: Python :: 3.7 | ||
Programming Language :: Python :: Implementation :: CPython | ||
Programming Language :: Python :: Implementation :: PyPy | ||
Topic :: Utilities | ||
license_file = LICENSE | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
|
||
[options] | ||
python_requires = >= 3.6 | ||
python_requires = >= 3.5 | ||
setup_requires = | ||
setuptools >= 38.6 | ||
pip >= 10 | ||
|
@@ -30,19 +33,21 @@ include_package_data = True | |
packages = find: | ||
install_requires = | ||
numpy | ||
pytz | ||
python-dateutil | ||
|
||
[options.extras_require] | ||
tests = | ||
pytest | ||
cov = | ||
pytest-cov | ||
coveralls | ||
flake8 | ||
mypy | ||
plot = | ||
xarray | ||
plot = | ||
xarray | ||
matplotlib | ||
timezone = | ||
pytz | ||
|
||
[options.entry_points] | ||
console_scripts = | ||
|
@@ -59,7 +64,6 @@ omit = | |
/home/travis/virtualenv/* | ||
*/site-packages/* | ||
*/bin/* | ||
*/build/* | ||
|
||
[coverage:report] | ||
exclude_lines = | ||
|
Oops, something went wrong.