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

Render leading zeros for years 0001-0999 #405

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Python package
# Create and test a Python package on multiple Python versions.
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/python

trigger:
- master

pool:
vmImage: ubuntu-latest
strategy:
matrix:
Python35:
python.version: '3.5'
Python37:
python.version: '3.10'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
displayName: 'Use Python $(python.version)'

- script: |
python -m pip install --upgrade pip
pip install -r requirements.txt
displayName: 'Install dependencies'

- script: |
pip install pytest pytest-azurepipelines
pytest
displayName: 'pytest'
9 changes: 8 additions & 1 deletion pyhive/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ def escape_sequence(self, item):
return '(' + ','.join(l) + ')'

def escape_datetime(self, item, format, cutoff=0):
dt_str = item.strftime(format)
if format.startswith('%Y'):
# patch for #404
dt_str = '{:0>4}{}'.format(
item.strftime('%Y'),
item.strftime(format.lstrip('%Y'))
)
else:
dt_str = item.strftime(format)
formatted = dt_str[:-cutoff] if cutoff and format.endswith(".%f") else dt_str
return "'{}'".format(formatted)

Expand Down
4 changes: 4 additions & 0 deletions pyhive/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ def test_escape_args(self):
("'2020-04-17'",))
self.assertEqual(escaper.escape_args((datetime.datetime(2020, 4, 17, 12, 0, 0, 123456),)),
("'2020-04-17 12:00:00.123456'",))
self.assertEqual(escaper.escape_args((datetime.date(2020, 4, 17),)),
("'2020-04-17'",))
self.assertEqual(escaper.escape_args((datetime.datetime(20, 4, 17, 12, 0, 0, 123456),)),
("'0020-04-17 12:00:00.123456'",))