Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.19.5 #20

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ Brewfile.lock.json
dist/
build/
.ipynb_checkpoints/
!notebooks/example.ipynb
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Chris Jellen
Copyright (c) 2023 Chris Jellen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 15 additions & 10 deletions ndbc_api/api/parsers/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class BaseParser:

HEADER_PREFIX = '#'
NAN_VALUES = ['MM']
DATE_PARSER = lambda x: datetime.strptime(x, '%Y %m %d %H %M')
DATE_PARSER = '%Y %m %d %H %M'
PARSE_DATES = ['YY', 'MM', 'DD', 'hh', 'mm']
INDEX_COL = None
INDEX_COL = False
REVERT_COL_NAMES = []

@classmethod
Expand Down Expand Up @@ -47,24 +47,29 @@ def _read_response(cls, response: dict,
names = cls.REVERT_COL_NAMES
if '(' in data[0]:
data = cls._clean_data(data)
# check whether to parse dates
if use_timestamp:
parse_dates = {'timestamp': cls.PARSE_DATES}
else:
parse_dates = False

try:
parse_dates = False
date_format = None
if use_timestamp:
parse_dates = [cls.PARSE_DATES]
date_format = cls.DATE_PARSER
df = pd.read_csv(
StringIO('\n'.join(data)),
names=names,
delim_whitespace=True,
na_values=cls.NAN_VALUES,
parse_dates=parse_dates,
date_parser=cls.DATE_PARSER,
index_col=cls.INDEX_COL,
parse_dates=parse_dates,
date_format=date_format,
)
if use_timestamp:
df.index.name = 'timestamp'

except (NotImplementedError, TypeError, ValueError) as e:
return pd.DataFrame()


# check whether to parse dates
return df

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion ndbc_api/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
LOGGER_NAME = 'NDBC-API'
DEFAULT_CACHE_LIMIT = 36
VERIFY_HTTPS = False
VERIFY_HTTPS = True
HTTP_RETRY = 5
HTTP_BACKOFF_FACTOR = 0.8
HTTP_DELAY = 2000
Expand Down
166 changes: 166 additions & 0 deletions notebooks/example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"os.chdir(\"..\")\n",
"sys.path.append(os.getcwd())"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'/Users/admin/Projects/GitHub/ndbc-api'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"os.getcwd()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from ndbc_api import NdbcApi"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "NdbcApi.__init__() got an unexpected keyword argument 'verify'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m api \u001b[39m=\u001b[39m NdbcApi(verify\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n",
"File \u001b[0;32m~/Projects/GitHub/ndbc-api/ndbc_api/utilities/singleton.py:12\u001b[0m, in \u001b[0;36mSingleton.__call__\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__call__\u001b[39m(\u001b[39mcls\u001b[39m, \u001b[39m*\u001b[39margs, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 11\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mcls\u001b[39m \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m_instances:\n\u001b[0;32m---> 12\u001b[0m \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m_instances[\u001b[39mcls\u001b[39m] \u001b[39m=\u001b[39m \u001b[39msuper\u001b[39;49m(Singleton,\n\u001b[1;32m 13\u001b[0m \u001b[39mcls\u001b[39;49m)\u001b[39m.\u001b[39;49m\u001b[39m__call__\u001b[39;49m(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 14\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mcls\u001b[39m\u001b[39m.\u001b[39m_instances[\u001b[39mcls\u001b[39m]\n",
"\u001b[0;31mTypeError\u001b[0m: NdbcApi.__init__() got an unexpected keyword argument 'verify'"
]
}
],
"source": [
"api = NdbcApi()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"api.stations()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"api.get_modes()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/admin/Projects/GitHub/ndbc-api/ndbc_api/api/parsers/_base.py:56: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
" df = pd.read_csv(\n",
"/Users/admin/Projects/GitHub/ndbc-api/ndbc_api/api/parsers/_base.py:56: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
" df = pd.read_csv(\n",
"/Users/admin/Projects/GitHub/ndbc-api/ndbc_api/api/parsers/_base.py:56: FutureWarning: The argument 'date_parser' is deprecated and will be removed in a future version. Please use 'date_format' instead, or read your data in as 'object' dtype and then call 'to_datetime'.\n",
" df = pd.read_csv(\n"
]
}
],
"source": [
"df_stdmet_tplm2 = api.get_data(\n",
" 'tplm2',\n",
" 'stdmet',\n",
" '2020-01-01',\n",
" '2022-01-01',\n",
" as_df=True\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_stdmet_tplm2.info(verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df_stdmet_tplm2.head(3).T"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"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.10.10"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "b2785e216e7a20b196a316c7e325ee02adc42957e613958a2188d56ea987fa80"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading