Skip to content

Commit 9cc326b

Browse files
authored
Merge pull request #38 from e-lo/pedro/pandas_compatibility
This makes GMNSPy compatible with Pandas 3.0, fixes #39. Adds testing across multiple versions of Python and Pandas. Fixes typos
2 parents 41b693f + e3f8ea8 commit 9cc326b

File tree

13 files changed

+57
-38
lines changed

13 files changed

+57
-38
lines changed

.github/workflows/documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ jobs:
1313
build-deploy-docs:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v2
16+
- uses: actions/checkout@v6
1717
with:
1818
fetch-depth: 0
1919
- name: Document which branch
2020
run: echo $DOC_REF_NAME
2121
- name: Set up Python
22-
uses: actions/setup-python@v2
22+
uses: actions/setup-python@v6
2323
with:
2424
python-version: '3.x'
2525
cache: 'pip'

.github/workflows/publish.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v6
2525
- name: Set up Python
26-
uses: actions/setup-python@v4
26+
uses: actions/setup-python@v6
2727
with:
2828
python-version: "3.x"
2929
- name: Install pypa/build
@@ -35,7 +35,7 @@ jobs:
3535
- name: Build a binary wheel and a source tarball
3636
run: python3 -m build
3737
- name: Store the distribution packages
38-
uses: actions/upload-artifact@v3
38+
uses: actions/upload-artifact@v4
3939
with:
4040
name: python-package-distributions
4141
path: dist/
@@ -55,7 +55,7 @@ jobs:
5555

5656
steps:
5757
- name: Download all the dists
58-
uses: actions/download-artifact@v3
58+
uses: actions/download-artifact@v4
5959
with:
6060
name: python-package-distributions
6161
path: dist/
@@ -78,7 +78,7 @@ jobs:
7878

7979
steps:
8080
- name: Download all the dists
81-
uses: actions/download-artifact@v3
81+
uses: actions/download-artifact@v4
8282
with:
8383
name: python-package-distributions
8484
path: dist/

.github/workflows/tests.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ on: [push, pull_request]
55
jobs:
66
linting:
77
runs-on: ubuntu-latest
8-
strategy:
9-
max-parallel: 4
10-
matrix:
11-
python-version: ['3.10']
128
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-python@v4
9+
- uses: actions/checkout@v6
10+
- uses: actions/setup-python@v6
1511
with:
16-
python-version: 3.x
17-
- uses: pre-commit/action@v3.0.0
12+
python-version: '3.13'
13+
- uses: pre-commit/action@v3.0.1
1814
with:
1915
extra_args: --all-files --verbose
2016
tests:
@@ -23,11 +19,11 @@ jobs:
2319
strategy:
2420
max-parallel: 4
2521
matrix:
26-
python-version: ['3.10']
22+
python-version: ['3.10', '3.11', '3.12', '3.13']
2723
steps:
28-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v6
2925
- name: Set up Python ${{ matrix.python-version }}
30-
uses: actions/setup-python@v4
26+
uses: actions/setup-python@v6
3127
with:
3228
python-version: ${{ matrix.python-version }}
3329
cache: 'pip'

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repos:
3838
- id: isort
3939
args: ["--profile", "black"]
4040
- repo: https://github.com/python-jsonschema/check-jsonschema
41-
rev: 0.14.3
41+
rev: 0.36.2
4242
hooks:
4343
- id: check-github-workflows
4444
- repo: http://github.com/pycqa/flake8

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ Get assigned. If you are working on issue, please tag yourself as the assignee (
4040

4141
Generally:
4242

43-
- Try to be backwards compatable to Python 3.10.
44-
- Be compatable with Numpy 2+, Pandas 2+, OSMNX 1+, PyProj 3.3+
43+
- Try to be backwards compatible to Python 3.10.
44+
- Be compatible with Numpy 2+, Pandas 2.x and 3.x, OSMNX 1+, PyProj 3.3+
4545
- Use PEP8 and autoformat with `black`
4646
- Use Google-style docstrings for all classes and methods
4747
- Test formatting and autoformat using `pre-commit`

gmnspy/in_out.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from gmnspy.validation import (
1717
apply_schema_to_df,
1818
check_required_files,
19-
update_resources_based_on_existance,
19+
update_resources_based_on_existence,
2020
validate_foreign_keys,
2121
)
2222

@@ -91,7 +91,7 @@ def read_gmns_network(data_directory: str, config: str = None, raise_error=False
9191
check_required_files(resource_df, raise_error)
9292

9393
# update resource dictionary based on what files are in the directory
94-
resource_df = update_resources_based_on_existance(resource_df)
94+
resource_df = update_resources_based_on_existence(resource_df)
9595

9696
# read each csv to a df and validate format
9797
# todo add paired schema

gmnspy/schema.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
from .utils import list_to_md_table, logger
2323

2424
SCHEMA_TO_PANDAS_TYPES = {
25-
"integer": "int64",
26-
"number": "float",
25+
"integer": "Int64",
26+
"number": "Float64",
2727
"string": "string",
2828
"any": "object",
29-
"boolean": "bool",
29+
"boolean": "boolean",
3030
}
3131

3232
FORMAT_TO_REGEX = {
@@ -37,6 +37,27 @@
3737
}
3838

3939

40+
def read_schema_for_resource(resource_df: pd.DataFrame, table_name: str, raise_error: bool) -> dict:
41+
"""
42+
Read in schema from schema json file and returns as dictionary.
43+
44+
##TODO validate schema itself
45+
46+
Args:
47+
schema_file: File location of the schema json file.
48+
49+
Returns: The schema as a dictionary
50+
"""
51+
matching_schema_paths = resource_df.loc[resource_df["name"] == table_name, "fullpath_schema"]
52+
if matching_schema_paths.empty:
53+
msg = f"FAIL. Could not find schema path for table {table_name}"
54+
logger.error(msg)
55+
if raise_error:
56+
raise Exception(msg)
57+
return dict()
58+
return read_schema(schema_file=matching_schema_paths.iloc[0])
59+
60+
4061
def read_schema(schema_file: str) -> dict:
4162
"""
4263
Read in schema from schema json file and returns as dictionary.
@@ -90,7 +111,7 @@ def read_config(config_file: str, data_dir: str = "", schema_dir: str = "") -> p
90111
## todo validate config
91112

92113
resource_df = pd.DataFrame(config["resources"])
93-
resource_df["required"].fillna(False, inplace=True)
114+
resource_df["required"] = resource_df["required"].fillna(False)
94115

95116
logger.info(str(resource_df))
96117

@@ -105,15 +126,15 @@ def read_config(config_file: str, data_dir: str = "", schema_dir: str = "") -> p
105126
resource_df["fullpath_schema"] = resource_df["schema"].apply(lambda x: join(schema_dir, x))
106127
logger.info(str(resource_df))
107128

108-
resource_df.set_index("name", drop=False, inplace=True)
129+
resource_df = resource_df.set_index("name", drop=False)
109130
return resource_df
110131

111132

112133
def document_schemas_to_md(schema_path: str = None, out_path: str = None) -> str:
113134
"""Create markdown for each **.schema.json file in schema_path.
114135
115136
Args:
116-
schema_path (str, optional): Path fo tlook for schema files.
137+
schema_path (str, optional): Path to look for schema files.
117138
Defaults to join(dirname(realpath(__file__)), "spec")
118139
out_path (str, optional): If specified, will write out resulting markdown to this file.
119140
Defaults to None.

gmnspy/validation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
from .foreign_keys import validate_foreign_keys
44
from .required_files import check_required_files
5-
from .resources_existance import update_resources_based_on_existance
5+
from .resources_existance import update_resources_based_on_existence
66
from .schema_to_df import apply_schema_to_df

gmnspy/validation/foreign_keys.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pandas as pd
66

7-
from gmnspy.schema import read_schema
7+
from gmnspy.schema import read_schema_for_resource
88
from gmnspy.utils import logger
99

1010

@@ -28,7 +28,9 @@ def validate_foreign_keys(gmns_net_d: Dict[str, pd.DataFrame], resource_df: pd.D
2828

2929
fkey_errors = []
3030
for table_name, df in gmns_net_d.items():
31-
schema = read_schema(schema_file=resource_df[resource_df["name"] == table_name]["fullpath_schema"][0])
31+
schema = read_schema_for_resource(resource_df, table_name, raise_error)
32+
if len(schema) == 0:
33+
continue
3234

3335
foreign_keys = [
3436
(f["name"], f["foreign_key"])

gmnspy/validation/required_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def check_required_files(resource_df: pd.DataFrame, raise_error=False) -> None:
1616
the the columns "fullpath", "name", and "required" (boolean).
1717
raise_error: Raises error if missing folder
1818
"""
19-
req_files = resource_df[resource_df["required"]]
19+
req_files = resource_df.query("required == True")
2020

2121
missing_required_files = req_files[req_files["fullpath"].apply(lambda x: not exists(x))][["name", "fullpath"]]
2222

0 commit comments

Comments
 (0)