Skip to content

Commit

Permalink
Merge pull request #300 from ocefpaf/pandas_2
Browse files Browse the repository at this point in the history
pandas 2.0 support
  • Loading branch information
ocefpaf authored Apr 6, 2023
2 parents 9779b3f + a2631e3 commit f4bece4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
16 changes: 11 additions & 5 deletions erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import httpx
import pytz
from pandas._libs.tslibs.parsing import parse_time_string
from pandas import to_datetime

ListLike = Union[List[str], Tuple[str]]
OptionalStr = Optional[str]
Expand Down Expand Up @@ -113,7 +113,11 @@ def _check_substrings(constraint):
return any([True for substring in substrings if substring in str(constraint)])


def parse_dates(date_time: Union[datetime, str]) -> float:
def parse_dates(
date_time: Union[datetime, str],
dayfirst=False,
yearfirst=False,
) -> float:
"""
Parse dates to ERDDAP internal format.
Expand All @@ -123,9 +127,11 @@ def parse_dates(date_time: Union[datetime, str]) -> float:
"""
if isinstance(date_time, str):
# pandas returns a tuple with datetime, dateutil, and string representation.
# we want only the datetime obj.
parse_date_time = parse_time_string(date_time)[0]
parse_date_time = to_datetime(
date_time,
dayfirst=dayfirst,
yearfirst=yearfirst,
).to_pydatetime()
else:
parse_date_time = date_time

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ dependencies = {file = ["requirements.txt"]}
[tool.setuptools_scm]
write_to = "erddapy/_version.py"
write_to_template = "__version__ = '{version}'"
tag_regex = "^(?P<prefix>v)?(?P<version>[^\\+]+)(?P<suffix>.*)?$"

[tool.pytest.ini_options]
markers = [
"web: marks tests require connection (deselect with '-m \"not web\"')",
"serial: marks tests that cannot be run in parallel (deselect with '-m \"not serial\"')",
]
filterwarnings = [
"error",
"error:::erddapy.*",
"ignore::UserWarning",
"ignore::RuntimeWarning",
]
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ geopandas
interrogate
joblib
jupyter
nbconvert<7.3.0
nbsphinx
netcdf4
pendulum>=2.0.1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
httpx
pandas>=0.20.3
pandas>=0.25.2,<3
pytz

0 comments on commit f4bece4

Please sign in to comment.