Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
dermatologist committed Nov 19, 2023
2 parents 483f2b1 + c0e0fe2 commit 1e26dd6
Show file tree
Hide file tree
Showing 30 changed files with 494 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [Choice] Python version: 3, 3.9, 3.8, 3.7, 3.6
ARG VARIANT=3.7
ARG VARIANT=3.10
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}

# [Option] Install Node.js
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"context": "..",
"args": {
// Update 'VARIANT' to pick a Python version: 3, 3.6, 3.7, 3.8, 3.9
"VARIANT": "3.7",
"VARIANT": "3.10",
// Options
"INSTALL_NODE": "false",
"NODE_VERSION": "lts/*"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2.3.1
with:
python-version: '3.8'
python-version: '3.10.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -24,7 +24,7 @@ jobs:
make -C docs/ html
cp docs/_config.yml docs/_build/html/_config.yml
- name: Deploy Docs 🚀
uses: JamesIves/github-pages-deploy-action@4.1.5
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs/_build/html # The folder the action should deploy.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2.3.1
with:
python-version: '3.8'
python-version: '3.10.13'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
max-parallel: 4
matrix:
python-version: [3.7]
python-version: [3.10.13]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
max-parallel: 4
matrix:
python-version: [3.8]
python-version: [3.10.13]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ formats:
- pdf

python:
version: 3.8
version: 3.10
install:
- requirements: docs/requirements.txt
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [Unreleased](https://github.com/dermatologist/pyomop/tree/HEAD)

[Full Changelog](https://github.com/dermatologist/pyomop/compare/3.2.0...HEAD)

**Closed issues:**

- SQLAlchemy 1.4 raises error [\#6](https://github.com/dermatologist/pyomop/issues/6)

## [3.2.0](https://github.com/dermatologist/pyomop/tree/3.2.0) (2023-01-20)

[Full Changelog](https://github.com/dermatologist/pyomop/compare/3.1.0...3.2.0)

## [3.1.0](https://github.com/dermatologist/pyomop/tree/3.1.0) (2021-09-17)

[Full Changelog](https://github.com/dermatologist/pyomop/compare/3.0.0...3.1.0)
Expand Down
71 changes: 62 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,67 @@ pip install pyomop
pip install -e .
```

## Usage
## Usage >= 4.0.0 (Async)
```
from pyomop import CdmEngineFactory, CdmVocabulary, CdmVector, Cohort, Vocabulary, metadata
from sqlalchemy.future import select
import datetime
import asyncio
cdm = CdmEngineFactory() # Creates SQLite database by default
# Postgres example (db='mysql' also supported)
# cdm = CdmEngineFactory(db='pgsql', host='', port=5432,
# user='', pw='',
# name='', schema='cdm6')
engine = cdm.engine
# Create Tables if required
asyncio.run(cdm.init_models(metadata))
# Create vocabulary if required
vocab = CdmVocabulary(cdm)
# vocab.create_vocab('/path/to/csv/files') # Uncomment to load vocabulary csv files
# Add a cohort
async with cdm.session() as session:
async with session.begin():
session.add(Cohort(cohort_definition_id=2, subject_id=100,
cohort_end_date=datetime.datetime.now(),
cohort_start_date=datetime.datetime.now()))
await session.commit()
# Query the cohort
stmt = select(Cohort).where(Cohort.subject_id == 100)
result = await session.execute(stmt)
for row in result.scalars():
print(row)
assert row.subject_id == 100
# Query the cohort pattern 2
cohort = await session.get(Cohort, 1)
print(cohort)
assert cohort.subject_id == 100
# Close session
await session.close()
await engine.dispose()
# Convert result to a pandas dataframe
vec = CdmVector()
vec.result = result
print(vec.df.dtypes)
# Execute SQL statetements
result = await vec.sql_df(cdm, 'TEST') # TEST is defined in sqldict.py
for row in result:
print(row)
result = await vec.sql_df(cdm, query='SELECT * from cohort')
for row in result:
print(row)
```

## Usage <=3.2.0

```
Expand All @@ -50,7 +110,7 @@ metadata.create_all(engine)
vocab = CdmVocabulary(cdm)
# vocab.create_vocab('/path/to/csv/files') # Uncomment to load vocabulary csv files
# SQLAlchemy as ORM
# Create a Cohort (SQLAlchemy as ORM)
session = cdm.session
session.add(Cohort(cohort_definition_id=2, subject_id=100,
cohort_end_date=datetime.datetime.now(),
Expand Down Expand Up @@ -82,13 +142,6 @@ print(vec.df.dtypes) # vec.df is a pandas dataframe
pyomop -help
```

## Troubleshoot

* sqlalchemy > 1.4 may not work. See [issue #6](https://github.com/dermatologist/pyomop/issues/6). Please downgrade sqlalchemy untill [issue #6](https://github.com/dermatologist/pyomop/issues/6) is fixed.
```
pip install sqlalchemy==1.3.24
```

## Other utils

**Want to convert FHIR to pandas data frame? Try [fhiry](https://github.com/dermatologist/fhiry)**
Expand Down
14 changes: 8 additions & 6 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile dev-requirements.in
#
Expand All @@ -10,16 +10,18 @@ attrs==21.2.0
# via pytest
babel==2.9.1
# via sphinx
backports.entry-points-selectable==1.1.0
backports-entry-points-selectable==1.1.0
# via virtualenv
certifi==2021.5.30
certifi==2022.12.7
# via requests
charset-normalizer==2.0.6
# via requests
commonmark==0.9.1
# via recommonmark
coverage[toml]==5.5
# via pytest-cov
# via
# coverage
# pytest-cov
distlib==0.3.2
# via virtualenv
docutils==0.17.1
Expand Down Expand Up @@ -66,7 +68,7 @@ pytest==6.2.5
# pytest-cov
pytest-cov==3.0.0
# via -r dev-requirements.in
pytz==2021.1
pytz==2023.3.post1
# via
# -c requirements.txt
# babel
Expand Down
13 changes: 1 addition & 12 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
# pyomop

OMOP CDM utils in Python


## Note

> This is the main page of your project's [Sphinx] documentation. It is
> formatted in [Markdown]. Add additional pages by creating md-files in
> `docs` or rst-files (formated in [reStructuredText]) and adding links to
> them in the `Contents` section below.
>
> Please check [Sphinx], [recommonmark] and [autostructify] for more information
> about how to document your project and how to configure your preferences.
*[by Bell Eapen](https://nuchange.ca)*

## Contents

Expand Down
30 changes: 15 additions & 15 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
#
# This file is autogenerated by pip-compile with python 3.8
# To update, run:
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile
#
click==8.0.3
aiosqlite==0.19.0
# via pyomop (setup.py)
inflect==5.3.0
# via sqlacodegen
numpy==1.21.4
# via pandas
pandas==1.3.5
click==8.1.7
# via pyomop (setup.py)
psycopg2-binary==2.9.3
greenlet==3.0.1
# via sqlalchemy
numpy==1.26.2
# via pandas
pandas==2.1.3
# via pyomop (setup.py)
python-dateutil==2.8.2
# via pandas
pytz==2021.1
pytz==2023.3.post1
# via pandas
six==1.16.0
# via python-dateutil
sqlacodegen==2.3.0
sqlalchemy==2.0.23
# via pyomop (setup.py)
sqlalchemy==1.3.24
# via
# pyomop (setup.py)
# sqlacodegen
typing-extensions==4.8.0
# via sqlalchemy
tzdata==2023.3
# via pandas
7 changes: 3 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers =
Development Status :: 4 - Beta
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering :: Information Analysis

[options]
Expand All @@ -35,11 +35,10 @@ package_dir =
# Add here dependencies of your project (semicolon/line-separated), e.g.
install_requires =
importlib-metadata; python_version<"3.8"
sqlacodegen
sqlalchemy<1.4
sqlalchemy>=1.4
click
pandas
psycopg2-binary
aiosqlite
# The usage of test_requires is discouraged, see `Dependency Management` docs
# tests_require = pytest; pytest-cov
# Require a specific Python version, e.g. Python 2.7 or >= 3.4
Expand Down
2 changes: 1 addition & 1 deletion src/pyomop/cdm6_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# coding: utf-8
from sqlalchemy import BigInteger, Column, Integer, Numeric, String, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import declarative_base

Base = declarative_base()
metadata = Base.metadata
Expand Down

0 comments on commit 1e26dd6

Please sign in to comment.