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

update dependencies, add job to test older pydantic #100

Merged
merged 1 commit into from
Nov 1, 2024
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
7 changes: 7 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ jobs:
matrix:
python: ['3.12']
os: [ubuntu-latest, macos-latest, windows-latest]
pydantic: ['pydantic==2.9.2']
# Test pydantic at lower boundary of requirement compatibility spec.
include:
- python: '3.12'
os: ubuntu-latest
pydantic: 'pydantic==2.6.4'
steps:
- uses: actions/checkout@v4
- name: Set up Python
Expand All @@ -58,6 +64,7 @@ jobs:
- name: Install dependencies.
run: |
python -m pip install --upgrade pip
pip install ${{ matrix.pydantic }}
pip install -e .[dev,docs]
pip list

Expand Down
17 changes: 9 additions & 8 deletions docs/examples/2022-10-pyodk-webinar.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,11 @@
}
],
"source": [
"json = client.submissions.get_table(form_id='participants')['value']\n",
"\n",
"import pandas as pd\n",
"df = pd.json_normalize(json, sep='-')\n",
"\n",
"json = client.submissions.get_table(form_id=\"participants\")[\"value\"]\n",
"\n",
"df = pd.json_normalize(json, sep=\"-\")\n",
"df.head(3)"
]
},
Expand Down Expand Up @@ -416,7 +417,7 @@
}
],
"source": [
"df.pets.value_counts().plot(kind='pie')"
"df.pets.value_counts().plot(kind=\"pie\")"
]
},
{
Expand Down Expand Up @@ -445,8 +446,8 @@
}
],
"source": [
"df['height_code'] = df.height_units.astype('category').cat.codes\n",
"df['pets_code'] = df.pets.astype('category').cat.codes\n",
"df[\"height_code\"] = df.height_units.astype(\"category\").cat.codes\n",
"df[\"pets_code\"] = df.pets.astype(\"category\").cat.codes\n",
"df.pets_code.corr(df.height_code)"
]
},
Expand Down Expand Up @@ -529,7 +530,7 @@
}
],
"source": [
"df['__system-submitterName'].value_counts().plot(kind='bar', rot=45)"
"df[\"__system-submitterName\"].value_counts().plot(kind=\"bar\", rot=45)"
]
},
{
Expand All @@ -547,7 +548,7 @@
"metadata": {},
"outputs": [],
"source": [
"df = df.drop(df.filter(regex = 'note_'), axis = 1)"
"df = df.drop(df.filter(regex=\"note_\"), axis=1)"
]
},
{
Expand Down
36 changes: 22 additions & 14 deletions docs/examples/basic-analysis-pandas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"metadata": {},
"outputs": [],
"source": [
"from pyodk.client import Client\n",
"import pandas as pd"
"import pandas as pd\n",
"from pyodk.client import Client"
]
},
{
Expand Down Expand Up @@ -228,9 +228,9 @@
],
"source": [
"with Client() as client:\n",
" submissions = client.submissions.get_table(form_id='fav_color')\n",
" df = pd.json_normalize(data=submissions['value'], sep='/')\n",
" \n",
" submissions = client.submissions.get_table(form_id=\"fav_color\")\n",
" df = pd.json_normalize(data=submissions[\"value\"], sep=\"/\")\n",
"\n",
"df.head(3)"
]
},
Expand Down Expand Up @@ -272,9 +272,11 @@
}
],
"source": [
"colors = {'g':'Green', 'o':'Orange', 'r':'Red', 'y':'Yellow'}\n",
"df['favorite_color_labels'] = df['favorite_color'].map(colors)\n",
"df['favorite_color_labels'].value_counts().plot(kind='bar', title='Count of favorite colors', xlabel=\"Color\", ylabel=\"Count\", rot=0)"
"colors = {\"g\": \"Green\", \"o\": \"Orange\", \"r\": \"Red\", \"y\": \"Yellow\"}\n",
"df[\"favorite_color_labels\"] = df[\"favorite_color\"].map(colors)\n",
"df[\"favorite_color_labels\"].value_counts().plot(\n",
" kind=\"bar\", title=\"Count of favorite colors\", xlabel=\"Color\", ylabel=\"Count\", rot=0\n",
")"
]
},
{
Expand Down Expand Up @@ -313,7 +315,9 @@
}
],
"source": [
"df['__system/reviewState'].value_counts().plot(kind='pie', title='Submission review state', ylabel='', rot=0)"
"df[\"__system/reviewState\"].value_counts().plot(\n",
" kind=\"pie\", title=\"Submission review state\", ylabel=\"\", rot=0\n",
")"
]
},
{
Expand Down Expand Up @@ -357,13 +361,17 @@
"import geopandas\n",
"from geopandas import GeoDataFrame\n",
"\n",
"world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n",
"base = world.plot(color='lightgrey', figsize=(15, 10))\n",
"world = geopandas.read_file(geopandas.datasets.get_path(\"naturalearth_lowres\"))\n",
"base = world.plot(color=\"lightgrey\", figsize=(15, 10))\n",
"base.set_axis_off()\n",
"\n",
"locations = pd.DataFrame(df['location/coordinates'].dropna().to_list(), columns=['x', 'y', 'alt'])\n",
"geodf = GeoDataFrame(locations, geometry=geopandas.points_from_xy(locations['x'], locations['y']))\n",
"geodf.plot(ax=base, marker='o', color='blue', markersize=15)"
"locations = pd.DataFrame(\n",
" df[\"location/coordinates\"].dropna().to_list(), columns=[\"x\", \"y\", \"alt\"]\n",
")\n",
"geodf = GeoDataFrame(\n",
" locations, geometry=geopandas.points_from_xy(locations[\"x\"], locations[\"y\"])\n",
")\n",
"geodf.plot(ax=base, marker=\"o\", color=\"blue\", markersize=15)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/beyond-library-methods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
}
],
"source": [
"response = client.get('/projects/7/forms/favorite_color/versions/2012060405.xlsx')\n",
"response = client.get(\"/projects/7/forms/favorite_color/versions/2012060405.xlsx\")\n",
"response.content[:150]"
]
},
Expand All @@ -188,7 +188,7 @@
"outputs": [],
"source": [
"if response.status_code == 200:\n",
" with open('2012060405.xlsx', 'wb') as f:\n",
" with open(\"2012060405.xlsx\", \"wb\") as f:\n",
" f.write(response.content)"
]
},
Expand Down Expand Up @@ -245,7 +245,7 @@
}
],
"source": [
"r = client.post('/projects/7/app-users', json={'displayName': 'Lab Tech'})\n",
"r = client.post(\"/projects/7/app-users\", json={\"displayName\": \"Lab Tech\"})\n",
"r.json()"
]
},
Expand Down
30 changes: 19 additions & 11 deletions docs/examples/working-with-repeats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
"metadata": {},
"outputs": [],
"source": [
"from pyodk.client import Client\n",
"import pandas as pd\n",
"from pyodk.client import Client\n",
"\n",
"client = Client().open()\n",
"submissions = client.submissions.get_table(form_id='simple_repeat', filter=\"__system/reviewState ne 'rejected'\")"
"submissions = client.submissions.get_table(\n",
" form_id=\"simple_repeat\", filter=\"__system/reviewState ne 'rejected'\"\n",
")"
]
},
{
Expand Down Expand Up @@ -195,7 +197,7 @@
}
],
"source": [
"subs_df = pd.json_normalize(data=submissions['value'], sep='/')\n",
"subs_df = pd.json_normalize(data=submissions[\"value\"], sep=\"/\")\n",
"subs_df.head(3)"
]
},
Expand Down Expand Up @@ -288,8 +290,12 @@
}
],
"source": [
"repeats = client.submissions.get_table(form_id='simple_repeat', table_name='Submissions.observation', filter=\"__system/reviewState ne 'rejected'\")\n",
"obs_df = pd.json_normalize(data=repeats['value'], sep='/')\n",
"repeats = client.submissions.get_table(\n",
" form_id=\"simple_repeat\",\n",
" table_name=\"Submissions.observation\",\n",
" filter=\"__system/reviewState ne 'rejected'\",\n",
")\n",
"obs_df = pd.json_normalize(data=repeats[\"value\"], sep=\"/\")\n",
"obs_df.head(3)"
]
},
Expand Down Expand Up @@ -511,7 +517,7 @@
}
],
"source": [
"subs_df.set_index('__id', inplace=True)\n",
"subs_df.set_index(\"__id\", inplace=True)\n",
"joined_df = obs_df.join(subs_df, on=\"__Submissions-id\")\n",
"joined_df.head(4)"
]
Expand Down Expand Up @@ -629,7 +635,7 @@
}
],
"source": [
"grouped = joined_df.groupby(['name', 'thing']).sum('count')[['count']]\n",
"grouped = joined_df.groupby([\"name\", \"thing\"]).sum(\"count\")[[\"count\"]]\n",
"grouped"
]
},
Expand All @@ -651,7 +657,7 @@
}
],
"source": [
"ax = grouped.unstack(level=0).plot(kind='bar')\n",
"ax = grouped.unstack(level=0).plot(kind=\"bar\")\n",
"ax.set_xlabel(\"Sighting\")\n",
"ax.set_ylabel(\"Total count\")\n",
"ax.legend().set_title(\"Data collector\")"
Expand Down Expand Up @@ -842,12 +848,14 @@
"\n",
"client = Client().open()\n",
"# The expand option includes all repeats in the json returned by get_table\n",
"submissions = client.submissions.get_table(form_id='simple_repeat', expand='*', filter=\"__system/reviewState ne 'rejected'\")\n",
"submissions = client.submissions.get_table(\n",
" form_id=\"simple_repeat\", expand=\"*\", filter=\"__system/reviewState ne 'rejected'\"\n",
")\n",
"# Flatten all repeats for each submission returned\n",
"df = pd.DataFrame([flatten_json(x) for x in submissions['value']])\n",
"df = pd.DataFrame([flatten_json(x) for x in submissions[\"value\"]])\n",
"\n",
"# Drop system columns so we can see more of the repeats\n",
"df.drop(list(df.filter(regex = '__system')), axis = 1, inplace = True)\n",
"df.drop(list(df.filter(regex=\"__system\")), axis=1, inplace=True)\n",
"df.head(3)"
]
}
Expand Down
2 changes: 1 addition & 1 deletion pyodk/_endpoints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class AuthService:
def __init__(self, session: "Session", cache_path: str | None = None) -> None:
self.session: "Session" = session
self.session: Session = session
self.cache_path: str = cache_path

def verify_token(self, token: str) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pyodk/_utils/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def send(self, request, **kwargs):

class Auth(AuthBase):
def __init__(self, session: "Session", username: str, password: str, cache_path: str):
self.session: "Session" = session
self.session: Session = session
self.username: str = username
self.password: str = password
self.service: AuthService = AuthService(session=session, cache_path=cache_path)
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ description = "The official Python library for ODK 🐍"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"requests==2.32.0", # HTTP with Central
"requests==2.32.3", # HTTP with Central
"toml==0.10.2", # Configuration files
"pydantic==2.6.4", # Data validation
"pydantic>=2.6.4,<2.9.3", # Data validation. Ensure actions verify.yml matches range.
]

[project.optional-dependencies]
# Install with `pip install pyodk[dev]`.
dev = [
"ruff==0.3.4", # Format and lint
"openpyxl==3.1.2", # Create test XLSX files
"ruff==0.7.1", # Format and lint
"openpyxl==3.1.5", # Create test XLSX files
"xlwt==1.3.0", # Create test XLS files
]
docs = [
Expand Down
Loading