Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rewrite install instructions for tutorial and remove top level install page * cleanup data checking * admonition styling * Update examples/tutorial/00_Setup.ipynb Co-authored-by: James A. Bednar <jbednar@continuum.io> * Update examples/tutorial/00_Setup.ipynb Co-authored-by: James A. Bednar <jbednar@continuum.io> * Update examples/tutorial/00_Setup.ipynb Co-authored-by: James A. Bednar <jbednar@continuum.io> --------- Co-authored-by: James A. Bednar <jbednar@continuum.io>
- Loading branch information
Showing
5 changed files
with
114 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pathlib | ||
import pandas as pd | ||
|
||
def check_data(file_path='../data/earthquakes-projected.parq'): | ||
""" | ||
Checks if the data file exists and reads it. | ||
Args: | ||
file_path (str, optional): The path to the parquet file. Default is '../data/earthquakes-projected.parq'. | ||
""" | ||
path = pathlib.Path(file_path) | ||
|
||
if not path.is_file(): | ||
print(f"Data file does not exist at {file_path}") | ||
|
||
try: | ||
columns = ['depth', 'id', 'latitude', 'longitude', 'mag', 'place', 'time', 'type'] | ||
data = pd.read_parquet(path, columns=columns, engine='fastparquet') | ||
data.head() | ||
print("Data exists and is readable!") | ||
except RuntimeError as e: | ||
print(f"The data cannot be read: {str(e)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import yaml | ||
import pathlib | ||
import sys | ||
from packaging.version import Version | ||
|
||
def get_required_versions(yaml_path): | ||
""" | ||
Reads the YAML configuration and extracts all package version requirements. | ||
Returns: | ||
dict: A dictionary mapping package names to their required versions. | ||
""" | ||
yaml_file_path = pathlib.Path(yaml_path) | ||
with open(yaml_file_path, 'r') as file: | ||
data = yaml.safe_load(file) | ||
packages = data['packages'] | ||
version_dict = {} | ||
for package in packages: | ||
if '==' in package: | ||
pkg, version = package.split('==') | ||
version_dict[pkg] = version | ||
return version_dict | ||
|
||
def check_packages(packages, yaml_path='../anaconda-project.yml'): | ||
""" | ||
Checks if specified packages are installed with correct versions as per the YAML configuration. | ||
Args: | ||
packages (list): A list of package names to check. | ||
""" | ||
required_versions = get_required_versions(yaml_path) | ||
error_found = False | ||
for pkg in packages: | ||
try: | ||
req_version = required_versions[pkg] | ||
installed_version = sys.modules[pkg].__version__ | ||
if Version(installed_version) < Version(req_version): | ||
print(f"Error: {pkg} expected version {req_version}, got {installed_version}") | ||
error_found = True | ||
except KeyError: | ||
print(f"{pkg} is not installed or not specified in the YAML configuration.") | ||
error_found = True | ||
|
||
if not error_found: | ||
print("All specified packages are correctly installed.") |