Skip to content

Commit

Permalink
release v0.2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-r-squared committed Aug 8, 2024
1 parent 7ed8f98 commit 3565100
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
12 changes: 7 additions & 5 deletions pirrtools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,29 @@ def __get_pirc_file():
return None


def __load_pirc_file():
def __load_pirc_file(verbose=False):
"""Loads the `.pirc` module from the `.pirc.py` file in the home directory and adds
the specified paths to the system path."""
pirc_file = __get_pirc_file()
if pirc_file:
spec = __importlib_util.spec_from_file_location("pirc", pirc_file)
pirc = __importlib_util.module_from_spec(spec)
spec.loader.exec_module(pirc)
print(f"Loaded {pirc_file.stem} module from {pirc_file}")
if verbose:
print(f"Loaded {pirc_file.stem} module from {pirc_file}")
if hasattr(pirc, "mypaths"):
for path in pirc.mypaths:
addpath(path, verbose=True)
addpath(path, verbose=verbose)


def __load_matplotlib_inline():
def __load_matplotlib_inline(verbose=False):
"""Loads the '%matplotlib inline' magic command in IPython if available."""
try:
ipython = get_ipython()
if ipython:
ipython.run_line_magic("matplotlib", "inline")
print("Loaded '%matplotlib inline'")
if verbose:
print("Loaded '%matplotlib inline'")
except ImportError:
pass

Expand Down
32 changes: 32 additions & 0 deletions pirrtools/pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,35 @@ def to_cache(self, *args, **kwargs):

reg_df("pirr")(UtilsAccessor)
reg_ser("pirr")(UtilsAccessor)


def create_class(level: int):
class I_N:
def __init__(self, pandas_obj):
self._validate(pandas_obj)
self._obj = pandas_obj
self._grp = self._obj.groupby(level=level)

@staticmethod
def _validate(obj):
if not isinstance(obj, (pd.DataFrame, pd.Series)):
raise AttributeError("The object must be a pandas DataFrame or Series.")
if level + 1 > obj.index.nlevels:
raise AttributeError(
f"The object must have at least {level + 1} index level(s)."
)

def __getattr__(self, name):
return getattr(self._grp, name)

def __dir__(self):
return dir(self._grp)

I_N.__name__ = f"I{level}"
return I_N


for i in range(0, 2):
cls = create_class(i)
reg_df(cls.__name__.lower())(cls)
reg_ser(cls.__name__.lower())(cls)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pirrtools"
version = "0.2.12" # Update this version number before you upload a new version to PyPI
version = "0.2.13" # Update this version number before you upload a new version to PyPI
description = "Collection of tools I use in my projects"
readme = "README.md"
license = { text = "MIT" }
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="pirrtools",
version="0.2.12", # Update this version number before releasing a new version
version="0.2.13", # Update this version number before releasing a new version
description="Collection of tools I use in my projects",
author="Sean Smith",
author_email="pirsquared.pirr@gmail.com",
Expand Down

0 comments on commit 3565100

Please sign in to comment.