Skip to content

Commit

Permalink
[main-major-12] (PR #27)
Browse files Browse the repository at this point in the history
Merge pull request #27 from syedalimohsinbukhari/testing
  • Loading branch information
syedalimohsinbukhari authored Dec 8, 2024
2 parents aa9f952 + 562b282 commit 9b1abfb
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 223 deletions.
6 changes: 1 addition & 5 deletions environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ name: mpyez
channels:
- conda-forge
- defaults
dependencies:
- python=3.9.*
- numpy==1.26.4
- matplotlib
- setuptools
dependencies: [ python=3.9, numpy==2, matplotlib, setuptools ]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build-system]
requires = ["setuptools", "numpy >=1.26.0, <2.1.0", "matplotlib"]
requires = ["setuptools", "numpy<2.1.0", "matplotlib"]

build-backend = "setuptools.build_meta:__legacy__"
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
numpy >=1.26.0,<2.1.0
numpy<2.1.0
matplotlib
setuptools
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def load_metadata():
long_description=readme,
long_description_content_type="text/markdown",
python_requires=">=3.9",
install_requires=["numpy >=1.26.0, <2.1.0", "matplotlib", "setuptools"],
include_package_data=True,
install_requires=["numpy<2.1.0", "matplotlib", "setuptools"],
classifiers=["License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
18 changes: 16 additions & 2 deletions src/mpyez/backend/eIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@


class EzFileErrs(Exception):
"""Base class for exceptions in EzFile."""
"""
Base class for exceptions in EzFile.
Notes
-----
This serves as the base class for all exceptions related to file operations
in the EzFile module. Specific exceptions should inherit from this class.
"""
pass


class LineNumberOutOfBounds(EzFileErrs):
"""Exception raised when a line number is out of bounds."""
"""
Raised when a specified line number is out of the bounds of the file.
Notes
-----
This error occurs when an operation attempts to access a line number
that exceeds the number of lines in the file or is less than 1.
"""
pass
60 changes: 60 additions & 0 deletions src/mpyez/backend/eList.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,92 @@


class EzListErrs(Exception):
"""
Base class for custom exceptions related to EzList operations.
All specific errors inherit from this class.
"""
pass


class AlphabetFound(EzListErrs):
"""
Raised when an unexpected alphabet character is found in the list.
Notes
-----
This error is typically raised when numeric operations are attempted
on a list that contains alphabetic strings.
"""
pass


class IndexOutOfList(EzListErrs):
"""
Raised when an index is out of the valid range of the list.
Notes
-----
This error occurs when an attempt is made to access or modify a list
using an index that exceeds the bounds of the list.
"""
pass


class UnequalElements(EzListErrs):
"""
Raised when lists have unequal elements where equality is expected.
Notes
-----
This error may be raised when operations requiring equal-length lists
or matching elements are attempted but the lists differ in size or content.
"""
pass


class GotAnUnknownValue(EzListErrs):
"""
Raised when an unknown or unexpected value is encountered.
Notes
-----
This error is raised when a list contains a value that does not conform
to the expected data type or range.
"""
pass


class ChildListLengthError(EzListErrs):
"""
Raised when a child list has an invalid length.
Notes
-----
This error is raised in scenarios where nested or child lists are
expected to meet specific length constraints but fail to do so.
"""
pass


class StringNotPassed(EzListErrs):
"""
Raised when a string input is expected but not provided.
Notes
-----
This error is raised when a function or operation requires a string
input but receives a non-string value instead.
"""
pass


class InvalidInputParameter(EzListErrs):
"""
Raised when an invalid parameter is passed to a function or method.
Notes
-----
This error indicates that one or more input arguments to a function
do not meet the expected type, range, or format.
"""
pass
12 changes: 12 additions & 0 deletions src/mpyez/backend/eOS.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@


class EzOsErrs(Exception):
"""
Base class for custom exceptions related to EzOs operations.
All specific errors inherit from this class.
"""
pass


class FileNotPresent(EzOsErrs):
"""
Raised when a specified file is not found in the expected location.
Notes
-----
This error is typically raised when a file operation (e.g., reading or writing)
is attempted on a file that does not exist.
"""
pass
29 changes: 26 additions & 3 deletions src/mpyez/backend/ePlotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,38 @@


class PlotError(Exception):
"""Basic PlotError class"""
"""
Base class for exceptions related to plotting operations.
Notes
-----
This serves as the parent class for all plotting-related errors.
Specific exceptions related to plot configuration or data issues
should inherit from this class.
"""
pass


class NoXYLabels(PlotError):
"""Custom class for missing x or y labels"""
"""
Raised when x or y labels are missing in a plot.
Notes
-----
This error occurs when a plot is expected to have labels for both
the x-axis and y-axis, but one or both are missing. Proper labeling
is often required for clarity in visualizations.
"""
pass


class OrientationError(PlotError):
"""Custom class for wrong orientation"""
"""
Raised when an invalid or unexpected orientation is used in a plot.
Notes
-----
This error occurs when the orientation parameter for a plot is set
incorrectly or does not match the expected format.
"""
pass
128 changes: 109 additions & 19 deletions src/mpyez/backend/uDict.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,131 @@
"""Created on Aug 17 23:51:58 2022."""

from typing import Any, Dict, List, Union

def change_value_to_list(input_dictionary):

def change_value_to_list(input_dictionary: Dict[Any, Any]) -> Dict[Any, List[Any]]:
"""
Converts all non-list values in a dictionary to lists.
Parameters
----------
input_dictionary : dict
The dictionary whose values need to be converted to lists.
Returns
-------
dict
A dictionary where all values are guaranteed to be lists.
"""
for key, value in input_dictionary.items():
if not isinstance(value, list):
input_dictionary[key] = [input_dictionary[key]]

input_dictionary[key] = [value]
return input_dictionary


def change_list_to_values(input_dictionary):
for key, value in input_dictionary.items():
if len(input_dictionary[key]) == 1:
input_dictionary[key] = input_dictionary[key][0]
def change_list_to_values(input_dictionary: Dict[Any, List[Any]]) -> Dict[Any, Union[Any, List[Any]]]:
"""
Converts single-element lists in a dictionary back to their single values.
Parameters
----------
input_dictionary : dict
The dictionary whose single-element list values need to be simplified.
Returns
-------
dict
A dictionary where single-element lists are replaced by their sole values.
"""
for key, value in input_dictionary.items():
if len(value) == 1:
input_dictionary[key] = value[0]
return input_dictionary


class PrettyPrint:
def __init__(self, input_dictionary: dict):
"""
A class for displaying dictionaries in a tabular format.
Parameters
----------
input_dictionary : dict
The dictionary to be formatted and displayed.
column_width : int, optional
Custom width for table columns (default is dynamically calculated).
alignment : str, optional
Alignment for table cells: 'left', 'center', or 'right' (default is 'center').
Attributes
----------
inp_dict : dict
The input dictionary stored for formatting and display.
column_width : int
Width of each column in the table.
alignment : str
Alignment configuration for table cells.
"""

def __init__(self, input_dictionary: Dict[Any, Any], column_width: int = None, alignment: str = "center"):
self.inp_dict = input_dictionary
self.column_width = column_width
self.alignment = alignment

def __get_max_width(self) -> int:
"""
Computes the maximum column width for formatting if not provided.
Returns
-------
int
The maximum width for the table columns.
"""
if self.column_width:
return self.column_width

def __get_max_width(self):
value_widths = [len(str(value)) for value in self.inp_dict.values()]
max_width = max(value_widths)
return max(max_width + 1, 71) if max_width % 2 == 0 else max(max_width, 71)

def __str__(self):
max_width = self.__get_max_width()
def __align_text(self, text: str, width: int) -> str:
"""
Aligns text within a given width based on the alignment setting.
width = (max_width - 1) // 2 - 1
pline = '-' * max_width + '\n'
Parameters
----------
text : str
The text to align.
width : int
The width of the column.
Returns
-------
str
The aligned text.
"""
if self.alignment == "left":
return text.ljust(width)
elif self.alignment == "right":
return text.rjust(width)
else: # Default to center
return text.center(width)

def __str__(self) -> str:
"""
Returns the formatted string representation of the dictionary.
Returns
-------
str
A tabular representation of the dictionary with enhanced aesthetics.
"""
max_width = self.__get_max_width()
column_width = (max_width - 1) // 2 - 1
separator_line = "+" + "-" * column_width + "+" + "-" * column_width + "+\n"

out = pline
out += f"|{'dict_key'.center(width)}|{'dict_value'.center(width)}|\n"
out += pline
out += '\n'.join([f"|{k.center(width)}|{v.center(width)}|" for k, v in self.inp_dict.items()]) + '\n'
out += pline
header = f"|{self.__align_text('dict_key', column_width)}|{self.__align_text('dict_value', column_width)}|\n"
rows = '\n'.join([f"|{self.__align_text(str(key), column_width)}|"
f"{self.__align_text(str(value), column_width)}|"
for key, value in self.inp_dict.items()])

return out
return separator_line + header + separator_line + rows + '\n' + separator_line
Loading

0 comments on commit 9b1abfb

Please sign in to comment.