Skip to content

Commit

Permalink
Merge pull request #71 from klieret/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
klieret committed Mar 15, 2021
2 parents 60c2b8a + 59c9b55 commit 95b5c83
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 69 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/python/black
rev: stable
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
language_version: python3.7
Expand All @@ -16,16 +16,16 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://gitlab.com/pycqa/flake8
rev: '' # pick a git hash / tag to point to
rev: '3.9.0' # pick a git hash / tag to point to
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: '' # Use the sha / tag you want to point at
rev: 'v0.812' # Use the sha / tag you want to point at
hooks:
- id: mypy
exclude: "conftest.py|^doc/examples/examples/|^doc/conf.py"
- repo: https://github.com/codespell-project/codespell
rev: ''
rev: 'v2.0.0'
hooks:
- id: codespell
args: ["-I", "codespell.txt"]
43 changes: 21 additions & 22 deletions ankipandas/ankidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class AnkiDataFrame(pd.DataFrame):
]

def __init__(self, *args, **kwargs):
""" Initializes a blank :class:`AnkiDataFrame`.
"""Initializes a blank :class:`AnkiDataFrame`.
.. warning::
Expand Down Expand Up @@ -81,7 +81,7 @@ def __init__(self, *args, **kwargs):

@property
def _constructor(self):
""" This needs to be overridden so that any DataFrame operations do not
"""This needs to be overridden so that any DataFrame operations do not
return a :class:`pandas.DataFrame` but a :class:`AnkiDataFrame`."""

return AnkiDataFrame
Expand Down Expand Up @@ -213,8 +213,7 @@ def db(self):

@property
def id(self):
""" Return note/card/review ID as :class:`pandas.Series` of integers.
"""
"""Return note/card/review ID as :class:`pandas.Series` of integers."""
if self._anki_table == "notes":
return self.nid
elif self._anki_table == "cards":
Expand Down Expand Up @@ -383,7 +382,7 @@ def did(self, value):

@property
def odid(self):
""" Original deck ID for cards in filtered deck as
"""Original deck ID for cards in filtered deck as
:class:`pandas.Series` of integers.
"""
if self._anki_table == "cards":
Expand Down Expand Up @@ -425,7 +424,7 @@ def merge_notes(
prepend="n",
prepend_clash_only=True,
):
""" Merge note table into existing dataframe.
"""Merge note table into existing dataframe.
Args:
inplace: If False, return new dataframe, else update old one
Expand Down Expand Up @@ -667,7 +666,7 @@ def list_models(self):
return sorted(self["nmodel"].unique())

def has_tag(self, tags: Optional[Union[Iterable[str], str]] = None):
""" Checks whether row has a certain tag ('ntags' column).
"""Checks whether row has a certain tag ('ntags' column).
Args:
tags: String or list thereof. In the latter case, True is returned
Expand Down Expand Up @@ -708,7 +707,7 @@ def _has_tag(other):
return self["ntags"].apply(bool)

def has_tags(self, tags: Optional[Union[Iterable[str], str]] = None):
""" Checks whether row contains at least the supplied tags.
"""Checks whether row contains at least the supplied tags.
Args:
tags: String or list thereof.
Expand Down Expand Up @@ -737,7 +736,7 @@ def has_tags(self, tags: Optional[Union[Iterable[str], str]] = None):
return self["ntags"].apply(_has_tags)

def add_tag(self, tags: Union[Sequence[str], str], inplace=False):
""" Adds tag ('ntags' column).
"""Adds tag ('ntags' column).
Args:
tags: String or list thereof.
Expand Down Expand Up @@ -765,7 +764,7 @@ def _add_tags(other):
self["ntags"] = self["ntags"].apply(_add_tags)

def remove_tag(self, tags: Union[Iterable[str], str, None], inplace=False):
""" Removes tag ('ntags' column).
"""Removes tag ('ntags' column).
Args:
tags: String or list thereof. If None, all tags are removed.
Expand Down Expand Up @@ -800,7 +799,7 @@ def _remove_tags(other):
def was_modified(
self, other: Optional[pd.DataFrame] = None, na=True, _force=False
):
""" Compare with original table, show which rows have changed.
"""Compare with original table, show which rows have changed.
Will only compare columns existing in both dataframes.
Args:
Expand Down Expand Up @@ -846,7 +845,7 @@ def was_modified(
def modified_columns(
self, other: Optional[pd.DataFrame] = None, _force=False, only=True
):
""" Compare with original table, show which columns in which rows
"""Compare with original table, show which columns in which rows
were modified.
Args:
Expand Down Expand Up @@ -879,7 +878,7 @@ def modified_columns(
)

def was_added(self, other: Optional[pd.DataFrame] = None, _force=False):
""" Compare with original table, show which rows were added.
"""Compare with original table, show which rows were added.
Args:
other: Compare with this :class:`pandas.DataFrame`.
Expand All @@ -905,7 +904,7 @@ def was_added(self, other: Optional[pd.DataFrame] = None, _force=False):
def was_deleted(
self, other: Optional[pd.DataFrame] = None, _force=False
) -> List:
""" Compare with original table, return deleted indizes.
"""Compare with original table, return deleted indizes.
Args:
other: Compare with this :class:`pandas.DataFrame`.
Expand Down Expand Up @@ -955,7 +954,7 @@ def _set_guid(self):
# ==========================================================================

def normalize(self, inplace=False, force=False):
""" Bring a :class:`AnkiDataFrame` from the ``raw`` format (i.e. the
"""Bring a :class:`AnkiDataFrame` from the ``raw`` format (i.e. the
exact format that Anki uses in its internal representation) to our
convenient format.
Expand Down Expand Up @@ -1057,7 +1056,7 @@ def normalize(self, inplace=False, force=False):
self._df_format = "ours"

def raw(self, inplace=False, force=False):
""" Bring a :class:`AnkiDataFrame` into the ``raw`` format (i.e. the
"""Bring a :class:`AnkiDataFrame` into the ``raw`` format (i.e. the
exact format that Anki uses in its internal representation) .
Args:
Expand Down Expand Up @@ -1198,7 +1197,7 @@ def raw(self, inplace=False, force=False):
# ==========================================================================

def summarize_changes(self, output="print") -> Optional[dict]:
""" Summarize changes that were made with respect to the table
"""Summarize changes that were made with respect to the table
as loaded from the database.
Args:
Expand Down Expand Up @@ -1233,7 +1232,7 @@ def summarize_changes(self, output="print") -> Optional[dict]:
# ==========================================================================

def _get_id(self, others=()) -> int:
""" Generate ID from timestamp and increment if it is already in use.
"""Generate ID from timestamp and increment if it is already in use.
.. warning::
Expand Down Expand Up @@ -1573,7 +1572,7 @@ def _handle_input(inpt, name, default, typ, options=None) -> List[Any]:
return all_cids

def _get_ids(self, n=1) -> List[int]:
""" Generate ID from timestamp and increment if it is already in use.
"""Generate ID from timestamp and increment if it is already in use.
Args:
n: Number of IDs to generate
Expand All @@ -1597,7 +1596,7 @@ def add_notes(
nusn=None,
inplace=False,
):
""" Add multiple new notes corresponding to one model.
"""Add multiple new notes corresponding to one model.
Args:
nmodel: Name of the model (must exist already, check
Expand Down Expand Up @@ -1839,7 +1838,7 @@ def add_note(
nusn=-1,
inplace=False,
):
""" Add new note.
"""Add new note.
.. note::
Expand Down Expand Up @@ -1994,7 +1993,7 @@ def help_cols(

@staticmethod
def help(ret=False) -> Union[str, None]:
""" Display short help text.
"""Display short help text.
Args:
ret: Return as string instead of printing it.
Expand Down
18 changes: 9 additions & 9 deletions ankipandas/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Collection:
def __init__(self, path=None, user=None):
""" Initialize :class:`~ankipandas.collection.Collection` object.
"""Initialize :class:`~ankipandas.collection.Collection` object.
Args:
path: (Search) path to database. See
Expand Down Expand Up @@ -125,22 +125,22 @@ def revs(self, value):
self.__items["revs"] = value

def empty_notes(self):
""" Similar :class:`ankipandas.ankidf.AnkiDataFrame`
to :attr:`notes`, but without any rows. """
"""Similar :class:`ankipandas.ankidf.AnkiDataFrame`
to :attr:`notes`, but without any rows."""
return AnkiDataFrame.init_with_table(self, "notes", empty=True)

def empty_cards(self):
""" Similar :class:`ankipandas.ankidf.AnkiDataFrame`
to :attr:`cards`, but without any rows. """
"""Similar :class:`ankipandas.ankidf.AnkiDataFrame`
to :attr:`cards`, but without any rows."""
return AnkiDataFrame.init_with_table(self, "cards", empty=True)

def empty_revs(self):
""" Similar :class:`ankipandas.ankidf.AnkiDataFrame`
to :attr:`revs`, but without any rows. """
"""Similar :class:`ankipandas.ankidf.AnkiDataFrame`
to :attr:`revs`, but without any rows."""
return AnkiDataFrame.init_with_table(self, "revs", empty=True)

def summarize_changes(self, output="print") -> Optional[Dict[str, dict]]:
""" Summarize changes that were made with respect to the table
"""Summarize changes that were made with respect to the table
as loaded from the database.
If notes/cards/etc. were not loaded at all (and hence also definitely
not modified), they do not appear in the output.
Expand Down Expand Up @@ -255,7 +255,7 @@ def write(
delete=False,
backup_folder: Union[PurePath, str] = None,
):
""" Creates a backup of the database and then writes back the new
"""Creates a backup of the database and then writes back the new
data.
.. danger::
Expand Down
7 changes: 4 additions & 3 deletions ankipandas/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def find_db(

@lru_cache(32)
def db_path_input(path: Union[str, PurePath] = None, user: str = None) -> Path:
""" Helper function to interpret user input of path to database.
"""Helper function to interpret user input of path to database.
1. If no path is given, we search through some default locations
2. If path points to a file: Take that file
Expand Down Expand Up @@ -232,7 +232,7 @@ def db_backup_file_name() -> str:


def get_anki_backup_folder(path: Union[str, PurePath], nexist="raise") -> Path:
""" Return path to Anki backup folder.
"""Return path to Anki backup folder.
Args:
path: Path to Aki database as :class:`Path`
Expand All @@ -256,7 +256,8 @@ def get_anki_backup_folder(path: Union[str, PurePath], nexist="raise") -> Path:


def backup_db(
db_path: Union[str, PurePath], backup_folder: Union[str, PurePath] = None,
db_path: Union[str, PurePath],
backup_folder: Union[str, PurePath] = None,
) -> Path:
"""
Back up database file.
Expand Down

0 comments on commit 95b5c83

Please sign in to comment.