Skip to content

Bugfix to handle case where DataFrame to be created is empty #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e59653e
add assertion to check for initialization, use ray 1.2.0 register_ser…
gtfierro May 5, 2021
2fbff72
is this check being run?
gtfierro May 5, 2021
bbaa169
remove print
gtfierro May 5, 2021
e2bb4f9
trying out custom serialize with a flag on connect
gtfierro May 20, 2021
74f5623
fix import
gtfierro May 20, 2021
c122166
fix import
gtfierro May 20, 2021
cd27a0b
try semver
gtfierro May 20, 2021
ab180fd
Merge remote-tracking branch 'upstream/master' into update-btrdb-cust…
gtfierro May 20, 2021
80517ca
modify setup and docs to use new repo
mchestnut91 May 24, 2021
8529c5c
updating copyright
mchestnut91 May 26, 2021
13e30ff
Merge pull request #2 from PingThingsIO/ch13150-modify-setup
mchestnut91 May 26, 2021
776731b
Merge pull request #1 from gtfierro/update-btrdb-custom-serialization
RamiroCope May 27, 2021
fc75ca4
Release v5.11.1
mchestnut91 Jun 10, 2021
d9e943d
Release v5.11.1
mchestnut91 Jun 10, 2021
e881d2e
Release v5.11.2
mchestnut91 Jun 10, 2021
f9d0c3d
make ray and semver dependencies optional
mchestnut91 Jun 10, 2021
59302b6
Merge pull request #3 from PingThingsIO/dependencies
mchestnut91 Jun 10, 2021
47ec4f4
Release v5.11.3
mchestnut91 Jun 10, 2021
2fd1003
Release v5.11.4
mchestnut91 Jun 10, 2021
3ca1d53
make sed cmd in release.sh compatatible with osx
mchestnut91 Jun 10, 2021
50fec53
Merge pull request #4 from PingThingsIO/ch13061-osx-release-fix
RamiroCope Jun 11, 2021
0f47f85
update build status in docs to show github actions
mchestnut91 Jun 25, 2021
67a491f
Merge pull request #5 from PingThingsIO/ch13382-update-build-badge
mchestnut91 Jun 25, 2021
d7eef59
Release v5.11.5
mchestnut91 Jun 25, 2021
bb16eb1
Release v5.11.6
mchestnut91 Jun 25, 2021
6bd543a
Update docs link in README
mchestnut91 Jun 28, 2021
14a851e
change link to docs in setup.py
mchestnut91 Jun 28, 2021
04e33a3
Merge pull request #6 from PingThingsIO/update_docs
mchestnut91 Jun 28, 2021
f07a5d1
update second docs link in README
mchestnut91 Jun 29, 2021
e9801fd
Update README.md
mchestnut91 Jun 29, 2021
a23e628
change path in setup back to old docs
mchestnut91 Jun 29, 2021
91156c2
Merge pull request #7 from PingThingsIO/update_docs
mchestnut91 Jun 29, 2021
31b3cb1
fixes Let's Encrypt cert issue (#9)
davidkonigsberg Sep 30, 2021
39ec946
bundles certifi certs as dependency (#10)
Oct 4, 2021
ff0824c
Release v5.11.7
looselycoupled Oct 4, 2021
6218233
Added code to handle case where dataframe created by to_dataframe is …
jacobmas Oct 27, 2021
a5a897c
stuff
jacobmas Nov 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bob.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

15 changes: 14 additions & 1 deletion btrdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from btrdb.exceptions import ConnectionError
from btrdb.version import get_version
from btrdb.utils.credentials import credentials_by_profile, credentials
from btrdb.utils.ray import register_serializer
from btrdb.stream import MINIMUM_TIME, MAXIMUM_TIME
from warnings import warn

##########################################################################
## Module Variables
Expand All @@ -40,7 +42,7 @@
def _connect(endpoints=None, apikey=None):
return BTrDB(Endpoint(Connection(endpoints, apikey=apikey).channel))

def connect(conn_str=None, apikey=None, profile=None):
def connect(conn_str=None, apikey=None, profile=None, shareable=False):
"""
Connect to a BTrDB server.

Expand All @@ -57,6 +59,12 @@ def connect(conn_str=None, apikey=None, profile=None):
The name of a profile containing the required connection information as
found in the user's predictive grid credentials file
`~/.predictivegrid/credentials.yaml`.
shareable: bool, default=False
Whether or not the connection can be "shared" in a distributed setting such
as Ray workers. If set to True, the connection can be serialized and sent
to other workers so that data can be retrieved in parallel; **however**, this
is less secure because it is possible for other users of the Ray cluster to
use your API key to fetch data.

Returns
-------
Expand All @@ -68,6 +76,11 @@ def connect(conn_str=None, apikey=None, profile=None):
if conn_str and profile:
raise ValueError("Received both conn_str and profile arguments.")

# check shareable flag and register custom serializer if necessary
if shareable:
warn("a shareable connection is potentially insecure; other users of the same cluster may be able to access your API key")
register_serializer(conn_str=conn_str, apikey=apikey, profile=profile)

# use specific profile if requested
if profile:
return _connect(**credentials_by_profile(profile))
Expand Down
22 changes: 18 additions & 4 deletions btrdb/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import re
import json
import certifi
import uuid as uuidlib

import grpc
Expand Down Expand Up @@ -65,12 +66,25 @@ def __init__(self, addrportstr, apikey=None):
# grpc bundles its own CA certs which will work for all normal SSL
# certificates but will fail for custom CA certs. Allow the user
# to specify a CA bundle via env var to overcome this
ca_bundle = os.getenv("BTRDB_CA_BUNDLE","")
if ca_bundle != "":
env_bundle = os.getenv("BTRDB_CA_BUNDLE", "")

# certifi certs are provided as part of this package install
# https://github.com/certifi/python-certifi
lib_certs = certifi.where()

ca_bundle = env_bundle

if ca_bundle == "":
ca_bundle = lib_certs
try:
with open(ca_bundle, "rb") as f:
contents = f.read()
else:
contents = None
except Exception:
if env_bundle != "":
# The user has given us something but we can't use it, we need to make noise
raise Exception("BTRDB_CA_BUNDLE(%s) env is defined but could not read file" % ca_bundle)
else:
contents = None

if apikey is None:
self.channel = grpc.secure_channel(
Expand Down
14 changes: 8 additions & 6 deletions btrdb/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,15 @@ def to_dataframe(streamset, columns=None, agg="mean", name_callable=None):


df = pd.DataFrame(to_dict(streamset,agg=agg))
df = df.set_index("time")

if agg == "all" and not streamset.allow_window:
stream_names = [[s.collection, s.name, prop] for s in streamset._streams for prop in _STAT_PROPERTIES]
df.columns=pd.MultiIndex.from_tuples(stream_names)
else:
df.columns = columns if columns else _stream_names(streamset, name_callable)
if not df.empty:
df = df.set_index("time")

if agg == "all" and not streamset.allow_window:
stream_names = [[s.collection, s.name, prop] for s in streamset._streams for prop in _STAT_PROPERTIES]
df.columns=pd.MultiIndex.from_tuples(stream_names)
else:
df.columns = columns if columns else _stream_names(streamset, name_callable)

return df

Expand Down
28 changes: 22 additions & 6 deletions btrdb/utils/ray.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from functools import partial

import ray

import btrdb
from btrdb.conn import BTrDB
from functools import partial

def register_serializer(conn_str=None, apikey=None, profile=None):
"""
Expand All @@ -22,8 +19,27 @@ def register_serializer(conn_str=None, apikey=None, profile=None):
found in the user's predictive grid credentials file
`~/.predictivegrid/credentials.yaml`.
"""
ray.register_custom_serializer(
BTrDB, serializer=btrdb_serializer, deserializer=partial(btrdb_deserializer, conn_str=conn_str, apikey=apikey, profile=profile))
try:
import ray
except ImportError:
raise ImportError("must pip install ray to register custom serializer")
try:
import semver
except ImportError:
raise ImportError("must pip install semver to register custom serializer")

assert ray.is_initialized(), "Need to call ray.init() before registering custom serializer"
# TODO: check the version using the 'semver' package?
ver = semver.VersionInfo.parse(ray.__version__)
if ver.major == 0:
ray.register_custom_serializer(
BTrDB, serializer=btrdb_serializer, deserializer=partial(btrdb_deserializer, conn_str=conn_str, apikey=apikey, profile=profile))
elif ver.major == 1 and ver.minor in range(2, 4):
# TODO: check different versions of ray?
ray.util.register_serializer(
BTrDB, serializer=btrdb_serializer, deserializer=partial(btrdb_deserializer, conn_str=conn_str, apikey=apikey, profile=profile))
else:
raise Exception("Ray version %s does not have custom serialization. Please upgrade to >= 1.2.0" % ray.__version__)

def btrdb_serializer(_):
"""
Expand Down
2 changes: 1 addition & 1 deletion btrdb/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
## Module Info
##########################################################################

__version_info__ = { 'major': 5, 'minor': 11, 'micro': 0, 'releaselevel': 'final'}
__version_info__ = { 'major': 5, 'minor': 11, 'micro': 7, 'releaselevel': 'final'}

##########################################################################
## Helper Functions
Expand Down
8 changes: 4 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
# -- Project information -----------------------------------------------------

project = 'btrdb'
copyright = '2019, Michael P. Andersen'
author = 'Michael P. Andersen'
copyright = '2021, Ping Things, Inc.'
author = 'PingThingsIO'

# The short X.Y version
version = get_version()
Expand Down Expand Up @@ -93,7 +93,7 @@
#
html_theme_options = {
'show_powered_by': False,
'github_user': 'BTrDB',
'github_user': 'PingThingsIO',
'github_repo': 'btrdb-python',
'travis_button': False,
'github_banner': False,
Expand Down Expand Up @@ -159,7 +159,7 @@
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'btrdb-python.tex', 'btrdb-python Documentation',
'Michael Andersen', 'manual'),
'PingThingsIO', 'manual'),
]


Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Welcome to btrdb docs!
======================

.. image:: https://img.shields.io/travis/BTrDB/btrdb-python/master.svg
:target: https://travis-ci.org/BTrDB/btrdb-python
.. image:: https://github.com/PingThingsIO/btrdb-python/actions/workflows/release.yaml/badge.svg
:target: https://github.com/PingThingsIO/btrdb-python/actions

.. image:: https://readthedocs.org/projects/btrdb/badge/?version=latest
:target: https://btrdb.readthedocs.io/en/latest/
Expand Down
4 changes: 2 additions & 2 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ fi

echo "Setting version to v$1.$2.$3"

VERION_CODE="__version_info__ = { 'major': $1, 'minor': $2, 'micro': $3, 'releaselevel': 'final'}"
sed -i "s/^__version_info__.*$/${VERION_CODE}/g" btrdb/version.py
VERSION_CODE="__version_info__ = { 'major': $1, 'minor': $2, 'micro': $3, 'releaselevel': 'final'}"
sed -i.bak "s/^__version_info__.*$/${VERSION_CODE}/g" btrdb/version.py

git add btrdb/version.py
git commit -m "Release v$1.$2.$3"
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ grpcio-tools>=1.19.0
pytz

# Misc libraries
pyyaml
pyyaml
certifi
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
## Basic information
NAME = "btrdb"
DESCRIPTION = "Bindings to interact with the Berkeley Tree Database using gRPC."
AUTHOR = "Michael Andersen, Allen Leis"
EMAIL = "michael@steelcode.com"
MAINTAINER = "Michael Andersen"
AUTHOR = "PingThingsIO"
EMAIL = "support@pingthings.io"
MAINTAINER = "PingThingsIO"
LICENSE = "BSD-3-Clause"
REPOSITORY = "https://github.com/BTrDB/btrdb-python"
REPOSITORY = "https://github.com/PingThingsIO/btrdb-python"
PACKAGE = "btrdb"
URL = "http://btrdb.io/"
DOCS_URL = "https://btrdb.readthedocs.io/en/latest/"
Expand Down