From cd1204823753aa4fd0dc1185b26de72547484f63 Mon Sep 17 00:00:00 2001 From: Jeff Klenzing <19592220+jklenzing@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:23:00 -0400 Subject: [PATCH] MAINT: ensure backward compat with pandas --- pysatNASA/instruments/methods/cdaweb.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pysatNASA/instruments/methods/cdaweb.py b/pysatNASA/instruments/methods/cdaweb.py index 04d37c5e..f85a7bde 100644 --- a/pysatNASA/instruments/methods/cdaweb.py +++ b/pysatNASA/instruments/methods/cdaweb.py @@ -18,6 +18,7 @@ import datetime as dt import numpy as np import os +from packaging.version import Version as pack_ver import pandas as pds import requests import tempfile @@ -845,9 +846,15 @@ def list_remote_files(tag='', inst_id='', start=None, stop=None, if 'year' in search_dir['keys']: url_list = [] if 'month' in search_dir['keys']: + # TODO(#242): remove if/else once support for older pandas is + # dropped. + if pack_ver(pds.__version__) >= pack_ver('2.2.0'): + freq_key = 'ME' + else: + freq_key = 'M' search_times = pds.date_range(start, stop + pds.DateOffset(months=1), - freq='ME') + freq=freq_key) for time in search_times: subdir = format_dir.format(year=time.year, month=time.month) url_list.append('/'.join((remote_url, subdir))) @@ -857,9 +864,16 @@ def list_remote_files(tag='', inst_id='', start=None, stop=None, + pds.DateOffset(days=1), freq='D') else: + + # TODO(#242): remove if/else once support for older pandas + # is dropped. + if pack_ver(pds.__version__) >= pack_ver('2.2.0'): + freq_key = 'YE' + else: + freq_key = 'Y' search_times = pds.date_range(start, stop + pds.DateOffset(years=1), - freq='YE') + freq=freq_key) for time in search_times: doy = int(time.strftime('%j')) subdir = format_dir.format(year=time.year, day=doy)