Skip to content

Commit

Permalink
Improve XKRXExchangeCalendar (#19)
Browse files Browse the repository at this point in the history
* Improve XKRXExchangeCalendar & Fix FutureWarning for indexing timezone-naive dt to timezone-aware index in ecal.py

* Remove unused import

* Update and run pre-commit & Fix for failing CI checks (benchmark, flake8)

* Fix missing import from pandas

* Upgrade minimum required pandas version from 1.0 to 1.1

* Upgrade requirements.txt

* Add test case, fix labor day

* Fix KoreanHoliday, CompositeCustomBusinessDay & Update KRX regular, adhoc holidays
  • Loading branch information
elbakramer authored Jun 20, 2021
1 parent 27d50fa commit 2acb51c
Show file tree
Hide file tree
Showing 31 changed files with 20,052 additions and 8,510 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ENV PIPX_HOME=/usr/local/py-utils \
PIPX_BIN_DIR=/usr/local/py-utils/bin
ENV PATH=${PATH}:${PIPX_BIN_DIR}
COPY .devcontainer/library-scripts/python-debian.sh /tmp/library-scripts/
RUN bash /tmp/library-scripts/python-debian.sh "none" "/usr/local" "${PIPX_HOME}" "${USERNAME}" "false" \
RUN bash /tmp/library-scripts/python-debian.sh "none" "/usr/local" "${PIPX_HOME}" "${USERNAME}" "false" \
&& apt-get clean -y && rm -rf /tmp/library-scripts

# [Option] Install Node.js
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/library-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

The contents of this folder will be automatically replaced with a file of the same name in the [vscode-dev-containers](https://github.com/microsoft/vscode-dev-containers) repository's [script-library folder](https://github.com/microsoft/vscode-dev-containers/tree/master/script-library) whenever the repository is packaged.

To retain your edits, move the file to a different location. You may also delete the files if they are not needed.
To retain your edits, move the file to a different location. You may also delete the files if they are not needed.
18 changes: 9 additions & 9 deletions .devcontainer/library-scripts/common-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
PACKAGE_LIST="${PACKAGE_LIST} libssl1.1"
fi

# Install appropriate version of libssl1.0.x if available
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
Expand All @@ -121,7 +121,7 @@ if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then

echo "Packages to verify are installed: ${PACKAGE_LIST}"
apt-get -y install --no-install-recommends ${PACKAGE_LIST} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )

PACKAGES_ALREADY_INSTALLED="true"
fi

Expand All @@ -135,19 +135,19 @@ fi
# Ensure at least the en_US.UTF-8 UTF-8 locale is available.
# Common need for both applications and things like the agnoster ZSH theme.
if [ "${LOCALE_ALREADY_SET}" != "true" ] && ! grep -o -E '^\s*en_US.UTF-8\s+UTF-8' /etc/locale.gen > /dev/null; then
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
LOCALE_ALREADY_SET="true"
fi

# Create or update a non-root user to match UID/GID.
if id -u ${USERNAME} > /dev/null 2>&1; then
# User exists, update if needed
if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
groupmod --gid $USER_GID $USERNAME
if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
groupmod --gid $USER_GID $USERNAME
usermod --gid $USER_GID $USERNAME
fi
if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
usermod --uid $USER_UID $USERNAME
fi
else
Expand All @@ -157,7 +157,7 @@ else
else
groupadd --gid $USER_GID $USERNAME
fi
if [ "${USER_UID}" = "automatic" ]; then
if [ "${USER_UID}" = "automatic" ]; then
useradd -s /bin/bash --gid $USERNAME -m $USERNAME
else
useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME
Expand All @@ -172,7 +172,7 @@ if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}"
fi

# ** Shell customization section **
if [ "${USERNAME}" = "root" ]; then
if [ "${USERNAME}" = "root" ]; then
USER_RC_PATH="/root"
else
USER_RC_PATH="/home/${USERNAME}"
Expand Down Expand Up @@ -286,7 +286,7 @@ install-oh-my()
echo "${CODESPACES_ZSH}" > ${OH_MY_INSTALL_DIR}/custom/themes/codespaces.zsh-theme
fi
# Shrink git while still enabling updates
cd ${OH_MY_INSTALL_DIR}
cd ${OH_MY_INSTALL_DIR}
git repack -a -d -f --depth=1 --window=1

if [ "${USERNAME}" != "root" ]; then
Expand Down
10 changes: 5 additions & 5 deletions .devcontainer/library-scripts/node-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ su ${USERNAME} -c "$(cat << EOF
# Do not update profile - we'll do this manually
export PROFILE=/dev/null
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source ${NVM_DIR}/nvm.sh
if [ "${NODE_VERSION}" != "" ]; then
nvm alias default ${NODE_VERSION}
fi
nvm clear-cache
nvm clear-cache
EOF
)" 2>&1

Expand All @@ -113,7 +113,7 @@ fi
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
[ -s "\$NVM_DIR/bash_completion" ] && . "\$NVM_DIR/bash_completion"
EOF
) | tee -a /etc/bash.bashrc >> /etc/zsh/zshrc
fi
) | tee -a /etc/bash.bashrc >> /etc/zsh/zshrc
fi

echo "Done!"
echo "Done!"
2 changes: 1 addition & 1 deletion .github/workflows/master-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
with:
config-name: release-drafter-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
rev: v3.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/flake8
rev: 3.9.1
hooks:
- id: flake8
- repo: https://github.com/psf/black
rev: 21.4b2
hooks:
- id: black
language_version: python
82 changes: 41 additions & 41 deletions etc/ecal
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ from __future__ import print_function
import sys

months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
]


Expand All @@ -36,43 +36,43 @@ def _render_month(calendar, year, month, print_year):

out = io.StringIO()

start = '{year}-{month}'.format(year=year, month=month)
start = "{year}-{month}".format(year=year, month=month)
if month == 12:
end = '{year}-{month}'.format(year=year + 1, month=1)
end = "{year}-{month}".format(year=year + 1, month=1)
else:
end = '{year}-{month}'.format(year=year, month=month + 1)
end = "{year}-{month}".format(year=year, month=month + 1)

days = pd.date_range(start, end, closed='left', utc=True)
days = pd.date_range(start, end, closed="left", utc=True)

title = months[month - 1]
if print_year:
title += ' {year}'.format(year=year)
title += " {year}".format(year=year)

print('{title:^28}'.format(title=title).rstrip(), file=out)
print(' Su Mo Tu We Th Fr Sa', file=out)
print("{title:^28}".format(title=title).rstrip(), file=out)
print(" Su Mo Tu We Th Fr Sa", file=out)
print(
' ' * (4 * ((days[0].weekday() + 1) % 7)),
end='',
" " * (4 * ((days[0].weekday() + 1) % 7)),
end="",
file=out,
)

for d in days:
if d.weekday() == 6:
print('', file=out)
print("", file=out)

if calendar.is_session(d):
a = b = ' '
a = b = " "
else:
a = '['
b = ']'
a = "["
b = "]"

print(
'{a}{d.day:>2}{b}'.format(a=a, d=d, b=b),
end='',
"{a}{d.day:>2}{b}".format(a=a, d=d, b=b),
end="",
file=out,
)

print('', file=out)
print("", file=out)
return out.getvalue()


Expand All @@ -82,32 +82,32 @@ def _concat_lines(strings, width):
for lines in as_lines:
missing_lines = max_lines - len(lines)
if missing_lines:
lines.extend([' ' * width] * missing_lines)
lines.extend([" " * width] * missing_lines)

rows = []
for row_parts in zip(*as_lines):
row_parts = list(row_parts)
for n, row_part in enumerate(row_parts):
missing_space = width - len(row_part)
if missing_space:
row_parts[n] = row_part + ' ' * missing_space
row_parts[n] = row_part + " " * missing_space

rows.append(' '.join(row_parts))
rows.append(" ".join(row_parts))

return '\n'.join(row.rstrip() for row in rows)
return "\n".join(row.rstrip() for row in rows)


def _int_arg(v, name):
try:
return int(v)
except ValueError:
error('%s must be an integer, got: %r' % (name, v))
error("%s must be an integer, got: %r" % (name, v))


def parse_args(argv):
usage = 'usage: %s CALENDAR [[[DAY] MONTH] YEAR]' % argv[0]
usage = "usage: %s CALENDAR [[[DAY] MONTH] YEAR]" % argv[0]

if len(argv) == 1 or '--help' in argv or '-h' in argv:
if len(argv) == 1 or "--help" in argv or "-h" in argv:
error(usage)

if len(argv) > 1:
Expand All @@ -125,11 +125,11 @@ def parse_args(argv):
year = now.year
month = now.month
elif len(argv) == 3:
year = _int_arg(argv[2], 'YEAR')
year = _int_arg(argv[2], "YEAR")
month = None
elif len(argv) == 4:
month = _int_arg(argv[2], 'MONTH')
year = _int_arg(argv[3], 'YEAR')
month = _int_arg(argv[2], "MONTH")
year = _int_arg(argv[3], "YEAR")
else:
error(usage)

Expand Down Expand Up @@ -157,9 +157,9 @@ def main(argv):
]
for row in range(4)
]
print('{year:^88}\n'.format(year=year).rstrip())
print('\n\n'.join(_concat_lines(cs, 28) for cs in month_strings))
print("{year:^88}\n".format(year=year).rstrip())
print("\n\n".join(_concat_lines(cs, 28) for cs in month_strings))


if __name__ == '__main__':
if __name__ == "__main__":
main(sys.argv)
Loading

0 comments on commit 2acb51c

Please sign in to comment.