Skip to content

Commit c575228

Browse files
authored
Merge pull request #80 from ocefpaf/sort_index
Sort index
2 parents 35bea95 + 70bc748 commit c575228

5 files changed

+17
-18
lines changed

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
files: requirements-dev.txt
1515

1616
- repo: https://github.com/psf/black
17-
rev: 23.12.1
17+
rev: 24.1.1
1818
hooks:
1919
- id: black
2020
language_version: python3
@@ -33,10 +33,10 @@ repos:
3333
- id: blackdoc
3434

3535
- repo: https://github.com/econchick/interrogate
36-
rev: 1.5.0
36+
rev: 237be78f9c6135fc1a620d211cdfdc5d3885082b
3737
hooks:
3838
- id: interrogate
39-
exclude: ^(docs|setup.py|tests)
39+
exclude: ^(docs|tests)
4040
args: [--config=pyproject.toml]
4141

4242
- repo: https://github.com/codespell-project/codespell
@@ -56,12 +56,12 @@ repos:
5656
- id: add-trailing-comma
5757

5858
- repo: https://github.com/astral-sh/ruff-pre-commit
59-
rev: v0.1.9
59+
rev: v0.1.15
6060
hooks:
6161
- id: ruff
6262

6363
- repo: https://github.com/tox-dev/pyproject-fmt
64-
rev: 1.5.3
64+
rev: 1.7.0
6565
hooks:
6666
- id: pyproject-fmt
6767

gliderpy/fetchers.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ def _to_pandas_multiple(glider_grab):
3030
glider_grab_copy = copy(glider_grab)
3131
for dataset_id in glider_grab_copy.datasets["Dataset ID"]:
3232
glider_grab_copy.fetcher.dataset_id = dataset_id
33-
df = glider_grab_copy.fetcher.to_pandas(
34-
index_col="time (UTC)",
35-
parse_dates=True,
36-
)
33+
df = glider_grab_copy.fetcher.to_pandas()
3734
dataset_url = glider_grab_copy.fetcher.get_download_url().split("?")[0]
3835
df = standardise_df(df, dataset_url)
3936
df_all.update({dataset_id: df})
@@ -45,8 +42,11 @@ def standardise_df(df, dataset_url):
4542
Standardise variable names in a dataset and add column for url
4643
"""
4744
df.columns = df.columns.str.lower()
48-
df.rename(columns=dict(server_parameter_rename), inplace=True)
49-
df.index.rename("time", inplace=True)
45+
df = df.set_index("time (utc)")
46+
df = df.rename(columns=server_parameter_rename)
47+
df.index = pd.to_datetime(df.index)
48+
# We need to sort b/c of the non-sequential submission of files due to the nature of glider data transmission.
49+
df = df.sort_index()
5050
df["dataset_url"] = dataset_url
5151
return df
5252

@@ -79,10 +79,7 @@ def to_pandas(self):
7979
:return: pandas dataframe with datetime UTC as index, multiple dataset_ids dataframes are stored in a dictionary
8080
"""
8181
if self.fetcher.dataset_id:
82-
df = self.fetcher.to_pandas(
83-
index_col="time (UTC)",
84-
parse_dates=True,
85-
)
82+
df = self.fetcher.to_pandas()
8683
elif not self.fetcher.dataset_id and self.datasets is not None:
8784
df_all = _to_pandas_multiple(self)
8885
# We need to reset to avoid fetching a single dataset_id when making multiple requests.
@@ -93,7 +90,7 @@ def to_pandas(self):
9390
f"Must provide a {self.fetcher.dataset_id} or `query` terms to download data.",
9491
)
9592

96-
# Standardize variable names.
93+
# Standardize variable names for the single dataset_id.
9794
dataset_url = self.fetcher.get_download_url().split("?")[0]
9895
df = standardise_df(df, dataset_url)
9996
return df

gliderpy/servers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
"""
55

6-
76
server_vars = {
87
"https://gliders.ioos.us/erddap": [
98
"latitude",
@@ -30,4 +29,5 @@
3029
"salinity (1)": "salinity",
3130
"temp (degree_celsius)": "temperature",
3231
"temperature (celsius)": "temperature",
32+
"time (utc)": "time",
3333
}

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ ignore = [
8686
"tests",
8787
"tests/*",
8888
]
89-
##
9089

9190
[tool.pytest.ini_options]
9291
filterwarnings = [

requirements-dev.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Pyarrow will be required in pandas 3.0,
2+
# added here for better performance and to avoid a deprecation warning.
13
cartopy
24
check-manifest
35
jupyter
@@ -6,6 +8,7 @@ nbconvert
68
nbsphinx
79
palettable
810
pre-commit
11+
pyarrow
912
pytest
1013
pytest-cov
1114
pytest-flake8

0 commit comments

Comments
 (0)