Skip to content

Commit

Permalink
fix python modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinLeeo committed May 30, 2024
1 parent 9e0e108 commit 850202d
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 40,634 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/python/tsfile/tsfile_pywrapper.cpython-310-x86_64-linux-gnu.so
/python/tsfile/libtsfile.so
/python/tsfile/libtsfile.so.1.0
/python/tsfile/tsfile_pywrapper.cpp


# intellij IDE files
Expand Down
55 changes: 36 additions & 19 deletions python/examlpes.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

import tsfile as ts
import numpy as np
import pandas as pd
import os

data_dir = "/home/colin/dev/tsfile/cpp/src/pywrapper/test.ts"
data_target = "/home/colin/dev/tsfile/cpp/src/pywrapper/test_write.ts"
data_dir = os.path.join(os.path.dirname(__file__), "test.tsfile")
table_name = "test_table"
columns = ["temperature", "level", "up"]

# write
time = np.arange(1, 1001, dtype=np.int64) # 1000
level = np.linspace(2000, 3000, num=1000, dtype=np.float32) # 1000
num = np.arange(10000, 11000, dtype= np.int64)
df = pd.DataFrame({"Time": time, "level": level, "num": num})

if os.path.exists(data_dir:
os.remove(data_dir)
ts.write_tsfile(data_target, table_name, df)


# read data we already write
tsfile_ret = ts.read_tsfile(data_target, table_name, ["level", "up"], chunksize=20)
print(tsfile_ret)

# with 100 chunksize
tsfile_ret = ts.read_tsfile(data_dir, table_name, columns, chunksize = 100)
print(tsfile_ret.shape)
columns.append("humi")

tsfile_ret = ts.read_tsfile(data_dir, table_name, columns)
print(tsfile_ret.shape)

Expand All @@ -28,28 +60,13 @@
tsfile_ret = ts.read_tsfile(data_dir, table_name, columns, start_time=50, end_time=100)
print(tsfile_ret.shape)


with ts.read_tsfile(data_dir, table_name, columns, iterator=True, start_time=100, end_time=500, chunksize=100) as reader:
for chunk in reader:
print(chunk.shape)


# write

time = np.arange(1, 1001, dtype=np.int64) # 1000
level = np.linspace(2000, 3000, num=1000, dtype=np.float32) # 1000
num = np.arange(10000, 11000, dtype= np.int64)
df = pd.DataFrame({"Time": time, "level": level, "num": num})

if os.path.exists(data_target):
# 如果存在,则删除
os.remove(data_target)
ts.write_tsfile(data_target, "table", df)


# read data we already write

tsfile_ret = ts.read_tsfile(data_target, "table", ["level", "num"], chunksize=20)
print(tsfile_ret)



Expand Down
21 changes: 20 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#


from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from Cython.Build import cythonize
Expand All @@ -13,7 +32,7 @@ def build_extensions(self):
build_ext.build_extensions(self)

libtsfile_path = os.path.join(os.path.dirname(__file__), "tsfile", "libtsfile.so")
source_include_dir = os.path.join(os.path.dirname(__file__), "..", "cwrapper", "TsFile-cwrapper.h")
source_include_dir = os.path.join(os.path.dirname(__file__), "..","cpp/src", "cwrapper", "TsFile-cwrapper.h")
target_include_dir = os.path.join(os.path.dirname(__file__), "tsfile", "TsFile-cwrapper.h")
shutil.copyfile(source_include_dir, target_include_dir)
include_dir = os.path.dirname(target_include_dir)
Expand Down
Binary file removed python/test.ts
Binary file not shown.
Binary file removed python/test_write.ts
Binary file not shown.
18 changes: 18 additions & 0 deletions python/tsfile/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

from .tsfile import read_tsfile, write_tsfile
19 changes: 19 additions & 0 deletions python/tsfile/common.pxd
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#


#cython: language_level=3str
cdef extern from "common/db_common.h" namespace "common":
cdef enum TSDataType:
Expand Down
18 changes: 18 additions & 0 deletions python/tsfile/tsfile.pxd
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

#cython: language_level=3
cdef extern from "./TsFile-cwrapper.h":
# common
Expand Down
18 changes: 18 additions & 0 deletions python/tsfile/tsfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

from .tsfile_pywrapper import tsfile_reader, tsfile_writer
from typing import overload
from pandas import DataFrame
Expand Down
Loading

0 comments on commit 850202d

Please sign in to comment.