Skip to content

Commit

Permalink
Merge cb9d6be into 87c33fa
Browse files Browse the repository at this point in the history
  • Loading branch information
pakallis committed May 5, 2020
2 parents 87c33fa + cb9d6be commit 449dd1b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.2
current_version = 0.1.0
commit = True
tag = True

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

0.1.0 (2020-05-05)
------------------
* Added static typing
* Removed unecessary params

0.0.2 (2020-05-04)
------------------

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Overview
:alt: Supported implementations
:target: https://pypi.org/project/pdmongo

.. |commits-since| image:: https://img.shields.io/github/commits-since/pakallis/python-pandas-mongo/v0.0.2.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/pakallis/python-pandas-mongo/v0.1.0.svg
:alt: Commits since latest release
:target: https://github.com/pakallis/python-pandas-mongo/compare/v0.0.2...master
:target: https://github.com/pakallis/python-pandas-mongo/compare/v0.1.0...master



Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
year = '2020'
author = 'Pavlos Kallis'
copyright = '{0}, {1}'.format(year, author)
version = release = '0.0.2'
version = release = '0.1.0'

pygments_style = 'trac'
templates_path = ['.']
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def read(*names, **kwargs):

setup(
name='pdmongo',
version='0.0.2',
version='0.1.0',
license='MIT',
description='Transfer data between pandas dataframes and MongoDB',
long_description='%s\n%s' % (
Expand Down
2 changes: 1 addition & 1 deletion src/pdmongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
pandas.DataFrame.to_mongo = to_mongo

__all__ = ['read_mongo', 'to_mongo']
__version__ = '0.0.2'
__version__ = '0.1.0'
53 changes: 31 additions & 22 deletions src/pdmongo/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from typing import Any
from typing import Dict
from typing import Iterator
from typing import List
from typing import Optional
from typing import Sequence
from typing import Union

from pandas import DataFrame
from pymongo import MongoClient
from pymongo.database import Database
from pymongo.results import InsertManyResult
from pymongo.uri_parser import parse_uri


def _get_db_instance(db):
def _get_db_instance(db: Union[str, Database]) -> MongoClient:
"""
Retrieve the pymongo.database.Database instance.
Expand All @@ -26,7 +36,7 @@ def _get_db_instance(db):
return db


def _handle_exists_collection(name, exists, db):
def _handle_exists_collection(name: str, exists: Optional[str], db: Database) -> None:
"""
Handles the `if_exists` argument of `to_mongo`.
Expand Down Expand Up @@ -55,7 +65,7 @@ def _handle_exists_collection(name, exists, db):
raise ValueError(f"'{exists}' is not valid for if_exists")


def _split_in_chunks(lst, chunksize):
def _split_in_chunks(lst: Sequence[Any], chunksize: int) -> Iterator[Sequence[Any]]:
"""
Splits a list in chunks based on provided chunk size.
Expand All @@ -73,7 +83,7 @@ def _split_in_chunks(lst, chunksize):
yield lst[i:i + chunksize]


def _validate_chunksize(chunksize):
def _validate_chunksize(chunksize: int) -> None:
"""
Raises the proper exception if chunksize is not valid.
Expand All @@ -89,14 +99,13 @@ def _validate_chunksize(chunksize):


def read_mongo(
collection,
query,
db,
index_col=None,
extra=None,
columns=None,
chunksize=None
):
collection: str,
query: List[Dict[str, Any]],
db: Union[str, Database],
index_col: Optional[Union[str, List[str]]] = None,
extra: Optional[Dict[str, Any]] = None,
chunksize: Optional[int] = None
) -> DataFrame:
"""
Read MongoDB query into a DataFrame.
Expand All @@ -115,8 +124,8 @@ def read_mongo(
The database to use
index_col : str or list of str, optional, default: None
Column(s) to set as index(MultiIndex).
extra : list, tuple or dict, optional, default: None
List of parameters to pass to find/aggregate method.
extra : dict, optional, default: None
List of parameters to pass to aggregate method.
chunksize : int, default None
If specified, return an iterator where `chunksize` is the number of
docs to include in each chunk.
Expand All @@ -143,14 +152,14 @@ def read_mongo(


def to_mongo(
frame,
name,
db,
if_exists="fail",
index=True,
index_label=None,
chunksize=None,
):
frame: DataFrame,
name: str,
db: Union[str, Database],
if_exists: Optional[str] = "fail",
index: Optional[bool] = True,
index_label: Optional[Union[str, Sequence[str]]] = None,
chunksize: Optional[int] = None,
) -> Union[List[InsertManyResult], InsertManyResult]:
"""
Write records stored in a DataFrame to a MongoDB collection.
Expand Down

0 comments on commit 449dd1b

Please sign in to comment.