Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

pandas .to_datetime() is deprecated as of 0.19.0 #385

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
38 changes: 23 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
language: python

addons:
apt:
packages:
- wget
env:
- TOX_ENV=py27
# - TOX_ENV=py32
# Disabling py32 tests until the following issue is fixed:
# pip 8.x breaks python 3.2 compatibility
# https://github.com/pypa/pip/issues/3390
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=pypy
- TOX_ENV=pypy3
- TOX_ENV=docs
- TOX_ENV=flake8
- TOX_ENV=coverage

matrix:
include:
- python: 2.7
env: TOX_ENV=py27
- python: pypy-5.3.1
env: TOX_ENV=pypy
- python: 3.4
env: TOX_ENV=py34
# An issue in travis-ci prevents this case from running
# Link to issue: https://github.com/travis-ci/travis-ci/issues/6304
# - python: pypy3.3-5.2-alpha1
# env: TOX_ENV=pypy3
- python: 3.4
env: TOX_ENV=docs
- python: 3.4
env: TOX_ENV=flake8
- python: 3.4
env: TOX_ENV=coverage

install:
- pip install tox
- pip install coveralls
- mkdir influxdb_install
- wget https://dl.influxdata.com/influxdb/releases/influxdb_0.13.0_amd64.deb
- wget https://dl.influxdata.com/influxdb/releases/influxdb_1.1.0_amd64.deb
- dpkg -x influxdb*.deb influxdb_install
script:
- export INFLUXDB_PYTHON_INFLUXD_PATH=$(pwd)/influxdb_install/usr/bin/influxd
- travis_wait 30 tox -e $TOX_ENV
- tox -e $TOX_ENV
after_success:
- if [ "$TOX_ENV" == "coverage" ] ; then coveralls; fi
notifications:
Expand Down
22 changes: 11 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@


InfluxDB-Python is a client for interacting with InfluxDB_. Maintained by @aviau (https://github.com/aviau).
InfluxDB-Python is a client for interacting with InfluxDB_.

**Help needed:** Development of this library is made by the community and help is needed. A co-maintainer would be welcome. To contribute, take a look at the issues list of simply contact @aviau.
This is a fork with some updates, see my pull requests on the original repo for this library: https://github.com/influxdata/influxdb-python/pulls/gansanay

.. image:: https://travis-ci.org/influxdata/influxdb-python.svg?branch=master
:target: https://travis-ci.org/influxdata/influxdb-python
.. image:: https://travis-ci.org/gansanay/influxdb-python.svg?branch=master
:target: https://travis-ci.org/gansanay/influxdb-python/

.. image:: https://readthedocs.org/projects/influxdb-python/badge/?version=latest&style
:target: http://influxdb-python.readthedocs.org/
:alt: Documentation Status

.. image:: https://img.shields.io/coveralls/influxdata/influxdb-python.svg
:target: https://coveralls.io/r/influxdata/influxdb-python
.. image:: https://img.shields.io/coveralls/gansanay/influxdb-python.svg
:target: https://coveralls.io/github/gansanay/influxdb-python
:alt: Coverage

.. _readme-about:
Expand All @@ -22,10 +22,10 @@ InfluxDB is an open-source distributed time series database, find more about Inf

.. _installation:

InfluxDB v0.8.X users
=====================
InfluxDB pre v1.1.0 users
=========================

InfluxDB 0.9 was released and it is the new recommended version. However, InfluxDB 0.8.x users may still use the legacy client by using ``from influxdb.influxdb08 import InfluxDBClient`` instead.
InfluxDB 1.1.0 was released and it is the new recommended version. InfluxDB 0.8.x users may still use the legacy client by using ``from influxdb.influxdb08 import InfluxDBClient`` instead.

Installation
============
Expand All @@ -43,9 +43,9 @@ On Debian/Ubuntu, you can install it with this command::
Dependencies
============

The InfluxDB-Python distribution is supported and tested on Python 2.7, 3.3, 3.4, PyPy and PyPy3.
The InfluxDB-Python distribution is supported and tested on Python 2.7, 3.4 and PyPy3.

**Note:** Python 3.2 is currently untested. See ``.travis.yml``.
**Note:** Pypy, Python 3.2 and 3.3 are currently untested. See ``.travis.yml``.

Main dependency is:

Expand Down
8 changes: 6 additions & 2 deletions influxdb/_dataframe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,12 @@ def _convert_dataframe_to_lines(self,
}.get(time_precision, 1)

# Make array of timestamp ints
time = ((dataframe.index.to_datetime().values.astype(int) /
precision_factor).astype(int).astype(str))
if isinstance(dataframe.index, pd.tseries.period.PeriodIndex):
time = ((dataframe.index.to_timestamp().values.astype(int) /
precision_factor).astype(int).astype(str))
else:
time = ((pd.to_datetime(dataframe.index).values.astype(int) /
precision_factor).astype(int).astype(str))

# If tag columns exist, make an array of formatted tag keys and values
if tag_columns:
Expand Down
7 changes: 6 additions & 1 deletion influxdb/influxdb08/dataframe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ def _convert_dataframe_to_json(self, dataframe, name, time_precision='s'):
isinstance(dataframe.index, pd.tseries.index.DatetimeIndex)):
raise TypeError('Must be DataFrame with DatetimeIndex or \
PeriodIndex.')
dataframe.index = dataframe.index.to_datetime()

if isinstance(dataframe.index, pd.tseries.period.PeriodIndex):
dataframe.index = dataframe.index.to_timestamp()
else:
dataframe.index = pd.to_datetime(dataframe.index)

if dataframe.index.tzinfo is None:
dataframe.index = dataframe.index.tz_localize('UTC')
dataframe['time'] = [self._datetime_to_epoch(dt, time_precision)
Expand Down
44 changes: 25 additions & 19 deletions influxdb/tests/server_tests/client_test_with_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ def test_default_retention_policy(self):
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'name': 'default',
'duration': '0',
{'name': 'autogen',
'duration': '0s',
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'default': True}
Expand All @@ -447,11 +447,11 @@ def test_create_retention_policy_default(self):

self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': False,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'},
'name': 'autogen'},
{'duration': '24h0m0s',
'default': True,
'replicaN': 1,
Expand All @@ -468,14 +468,17 @@ def test_create_retention_policy_default(self):

def test_create_retention_policy(self):
self.cli.create_retention_policy('somename', '1d', 1)
# NB: creating a retention policy without specifying
# shard group duration
# leads to a shard group duration of 1 hour
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': True,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'},
'name': 'autogen'},
{'duration': '24h0m0s',
'default': False,
'replicaN': 1,
Expand All @@ -491,18 +494,19 @@ def test_alter_retention_policy(self):
# Test alter duration
self.cli.alter_retention_policy('somename', 'db',
duration='4d')
# NB: altering retention policy doesn't change shard group duration
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': True,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'},
'name': 'autogen'},
{'duration': '96h0m0s',
'default': False,
'replicaN': 1,
'shardGroupDuration': u'24h0m0s',
'shardGroupDuration': u'1h0m0s',
'name': 'somename'}
],
rsp
Expand All @@ -511,18 +515,19 @@ def test_alter_retention_policy(self):
# Test alter replication
self.cli.alter_retention_policy('somename', 'db',
replication=4)
# NB: altering retention policy doesn't change shard group duration
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': True,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'},
'name': 'autogen'},
{'duration': '96h0m0s',
'default': False,
'replicaN': 4,
'shardGroupDuration': u'24h0m0s',
'shardGroupDuration': u'1h0m0s',
'name': 'somename'}
],
rsp
Expand All @@ -531,18 +536,19 @@ def test_alter_retention_policy(self):
# Test alter default
self.cli.alter_retention_policy('somename', 'db',
default=True)
# NB: altering retention policy doesn't change shard group duration
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': False,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'},
'name': 'autogen'},
{'duration': '96h0m0s',
'default': True,
'replicaN': 4,
'shardGroupDuration': u'24h0m0s',
'shardGroupDuration': u'1h0m0s',
'name': 'somename'}
],
rsp
Expand All @@ -558,11 +564,11 @@ def test_alter_retention_policy_invalid(self):
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': True,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'},
'name': 'autogen'},
{'duration': '24h0m0s',
'default': False,
'replicaN': 1,
Expand All @@ -580,11 +586,11 @@ def test_drop_retention_policy(self):
rsp = self.cli.get_list_retention_policies()
self.assertEqual(
[
{'duration': '0',
{'duration': '0s',
'default': True,
'replicaN': 1,
'shardGroupDuration': u'168h0m0s',
'name': 'default'}
'name': 'autogen'}
],
rsp
)
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[tox]
envlist = py34, py27, pypy, flake8
envlist = py27, py34, pypy, pypy3, flake8, coverage, docs

[testenv]
passenv = INFLUXDB_PYTHON_INFLUXD_PATH
setenv = INFLUXDB_PYTHON_SKIP_SERVER_TESTS=False
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
py27,py32,py33,py34,py26: pandas
py27,py34: pandas
# Only install pandas with non-pypy interpreters
commands = nosetests -v --with-doctest {posargs}

Expand Down