Skip to content
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

Deal with np.int_ on Windows, handle missing __INDEX__ #943

Merged
merged 4 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 40 additions & 40 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,46 @@ jobs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/*coverage.xml'

# - job: 'Windows'
# pool:
# vmImage: 'vs2017-win2016'

# strategy:
# matrix:
# Python37:
# python.version: '3.7'
# python_flag: ''

# steps:
# - task: UsePythonVersion@0
# inputs:
# versionSpec: '$(python.version)'
# architecture: 'x64'

# - task: NodeTool@0
# inputs:
# versionSpec: '12.x'

# - script: |
# which python > python.txt
# set /p PYTHON=<python.txt
# ln -s %PYTHON% %PYTHON%$(python.version)
# python --version
# which python$(python.version)
# displayName: "Which python"

# - script: |
# python -m pip install numpy pyarrow==0.15.1
# displayName: "Python deps"

# - script: npm install -g yarn
# displayName: "Install Yarn"

# - script: yarn
# displayName: 'Install Deps'

# - script: yarn build_python --ci $(python_flag)
# displayName: 'build'
- job: 'Windows'
pool:
vmImage: 'vs2017-win2016'

strategy:
matrix:
Python37:
python.version: '3.7'
python_flag: ''

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
architecture: 'x64'

- task: NodeTool@0
inputs:
versionSpec: '12.x'

- script: |
which python > python.txt
set /p PYTHON=<python.txt
ln -s %PYTHON% %PYTHON%$(python.version)
python --version
which python$(python.version)
displayName: "Which python"

- script: |
python -m pip install numpy pyarrow==0.15.1
displayName: "Python deps"

- script: npm install -g yarn
displayName: "Install Yarn"

- script: yarn
displayName: 'Install Deps'

- script: yarn build_python --ci $(python_flag)
displayName: 'build'


- job: 'Mac'
Expand Down
7 changes: 5 additions & 2 deletions python/perspective/perspective/src/numpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ namespace numpy {
/**
* Catch common type mismatches and fill iteratively when a numpy dtype is of greater bit width than the Perspective t_dtype:
* - when `np_dtype` is int64 and `t_dtype` is `DTYPE_INT32` or `DTYPE_FLOAT64`
* - when `np_dtype` is int32 and `t_dtype` is `DTYPE_INT64` or `DTYPE_FLOAT64`, which can happen on windows where np::int_ is int32
* - when `np_dtype` is float64 and `t_dtype` is `DTYPE_INT32` or `DTYPE_INT64`
* - when `type` is float64 and `np_dtype` is `DTYPE_FLOAT32` or `DTYPE_FLOAT64`
*
* These errors occur frqeuently when a Table is created from non-numpy data or schema, then updated with a numpy array.
* In these cases, the `t_dtype` of the Table supercedes the array dtype.
*/
bool should_iter = (np_dtype == DTYPE_INT64 && (type == DTYPE_INT32 || type == DTYPE_FLOAT64)) || \
(np_dtype == DTYPE_INT32 && (type == DTYPE_INT64 || type == DTYPE_FLOAT64)) || \
(np_dtype == DTYPE_FLOAT64 && (type == DTYPE_INT32 || type == DTYPE_INT64)) || \
(type == DTYPE_INT64 && (np_dtype == DTYPE_FLOAT32 || np_dtype == DTYPE_FLOAT64));

Expand Down Expand Up @@ -238,13 +240,13 @@ namespace numpy {
}

double fval = item.cast<double>();
if (fval > 2147483647 || fval < -2147483648) {
if (!is_update && (fval > 2147483647 || fval < -2147483648)) {
binding::WARN("Promoting column `%s` to float from int32", name);
tbl.promote_column(name, DTYPE_FLOAT64, i, true);
col = tbl.get_column(name);
type = DTYPE_FLOAT64;
col->set_nth(i, fval);
} else if (isnan(fval)) {
} else if (!is_update && isnan(fval)) {
binding::WARN("Promoting column `%s` to string from int32", name);
tbl.promote_column(name, DTYPE_STR, i, false);
col = tbl.get_column(name);
Expand Down Expand Up @@ -423,6 +425,7 @@ namespace numpy {

// We fill by object when `np_dtype`=object, or if there are type mismatches between `np_dtype` and `type`.
bool types_mismatched = (np_dtype == DTYPE_INT64 && (type == DTYPE_INT32 || type == DTYPE_FLOAT64)) || \
(np_dtype == DTYPE_INT32 && (type == DTYPE_INT64 || type == DTYPE_FLOAT64)) || \
(np_dtype == DTYPE_FLOAT64 && (type == DTYPE_INT32 || type == DTYPE_INT64)) || \
(type == DTYPE_INT64 && (np_dtype == DTYPE_FLOAT32 || np_dtype == DTYPE_FLOAT64));

Expand Down
3 changes: 2 additions & 1 deletion python/perspective/perspective/table/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# the Apache License 2.0. The full license can be found in the LICENSE file.
#

import os
import pandas
from functools import partial, wraps
from random import random
Expand Down Expand Up @@ -446,7 +447,7 @@ def to_csv(self, **options):
Returns:
:obj:`str`: A CSV-formatted string containing the serialized data.
'''
return self.to_df(**options).to_csv(date_format=options.pop("date_format", "%Y/%m/%d %H:%M:%S"))
return self.to_df(**options).to_csv(date_format=options.pop("date_format", "%Y/%m/%d %H:%M:%S"), line_terminator='\r\n' if os.name == 'nt' else '\n')

@wraps(to_records)
def to_json(self, **options):
Expand Down
Loading