Skip to content

Commit

Permalink
More IPython imports (#188)
Browse files Browse the repository at this point in the history
* more

* more

* more
  • Loading branch information
dycw authored Aug 16, 2024
1 parent 12e239d commit 95f0c68
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[bumpversion]
current_version = 0.1.185
current_version = 0.1.186
181 changes: 102 additions & 79 deletions ipython/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
)
from zoneinfo import ZoneInfo

builtins.print(f"{dt.datetime.now():%Y-%m-%d %H:%M:%S}: Running `startup.py`...") # noqa: DTZ005, T201


_ = [
AbstractSet,
Annotated,
Expand Down Expand Up @@ -252,7 +255,6 @@
platform,
poplib,
pprint,
pprint,
product,
random,
re,
Expand Down Expand Up @@ -341,6 +343,24 @@

alt.data_transformers.enable("vegafusion")

try:
from utilities.altair import (
plot_dataframes,
plot_intraday_dataframe,
save_chart,
save_charts_as_pdf,
vconcat_charts,
)
except ModuleNotFoundError:
pass
else:
_ = [
plot_dataframes,
plot_intraday_dataframe,
save_chart,
save_charts_as_pdf,
vconcat_charts,
]

try:
from beartype import beartype
Expand Down Expand Up @@ -527,20 +547,25 @@
try:
import more_itertools
import more_itertools as mi
from more_itertools import split_at
from more_itertools import partition, split_at
except ModuleNotFoundError:
pass
else:
_ = [mi, more_itertools, split_at]
_ = [mi, more_itertools, partition, split_at]

try:
import utilities
from utilities.more_itertools import (
always_iterable,
one,
partition_typeguard,
peekable,
)
except ModuleNotFoundError:
from more_itertools import always_iterable, one, peekable

_ = [always_iterable, one, peekable]
else:
_ = utilities

_ = [always_iterable, one, partition_typeguard, peekable]

try:
import numpy # noqa: ICN001
Expand Down Expand Up @@ -722,13 +747,18 @@
Week,
)
except ModuleNotFoundError:
try:
from utilities.pandas import IndexS
except ModuleNotFoundError:
pass
else:
_ = [IndexS]
try:
from utilities.pickle import read_pickle
except ModuleNotFoundError:
pass
else:
_ = [read_pickle]

else:
_ = [
BDay,
Expand Down Expand Up @@ -936,7 +966,12 @@
struct,
when,
]

try:
from utilities.polars import check_polars_dataframe
except ModuleNotFoundError:
pass
else:
_ = [check_polars_dataframe]

try:
from pqdm.processes import pqdm
Expand All @@ -955,6 +990,20 @@
_ = [pydantic, BaseModel]


try:
from pytest import fixture, mark, param # noqa: PT013
except ModuleNotFoundError:
pass
else:
_ = [fixture, mark, param]

try:
from utilities.pytest import throttle
except ModuleNotFoundError:
pass
else:
_ = [throttle]

try:
import requests
except ModuleNotFoundError:
Expand Down Expand Up @@ -998,12 +1047,24 @@
import sqlalchemy
import sqlalchemy as sqla
import sqlalchemy.orm
from sqlalchemy import create_engine, func, select
from sqlalchemy import func, select
except ModuleNotFoundError:
pass
else:
_ = [sqla, sqlalchemy, sqlalchemy.orm, create_engine, select, func]
_ = [sqla, sqlalchemy, sqlalchemy.orm, select, func]
try:
import utilities
except ModuleNotFoundError:
from utilities.sqlalchemy import (
create_engine,
get_table,
insert_items,
insert_items_async,
)

_ = [create_engine, get_table, insert_items, insert_items_async]
else:
_ = utilities

try:
import streamlit
Expand Down Expand Up @@ -1070,6 +1131,7 @@
from utilities.pickle import read_pickle, write_pickle
from utilities.re import extract_group, extract_groups
from utilities.text import ensure_str
from utilities.timer import Timer
from utilities.types import (
ensure_class,
ensure_datetime,
Expand All @@ -1093,6 +1155,7 @@
Month,
SECOND,
TOKYO,
Timer,
US_CENTRAL,
US_EASTERN,
UTC,
Expand Down Expand Up @@ -1133,82 +1196,51 @@
serialize_month,
write_pickle,
]
try:
from utilities.altair import (
plot_dataframes,
plot_intraday_dataframe,
save_chart,
save_charts_as_pdf,
vconcat_charts,
)
except ModuleNotFoundError:
pass
else:
_ = [
plot_dataframes,
plot_intraday_dataframe,
save_chart,
save_charts_as_pdf,
vconcat_charts,
]
try:
from utilities.atomicwrites import writer
except ModuleNotFoundError:
pass
else:
_ = [writer]
try:
from utilities.more_itertools import (
always_iterable,
partition_typeguard,
peekable,
)
except ModuleNotFoundError:
pass
else:
_ = [always_iterable, partition_typeguard, peekable]
try:
from utilities.jupyter import show
except ModuleNotFoundError:
pass
else:
_ = [show]
try:
from utilities.pandas import IndexS
except ModuleNotFoundError:
pass
else:
_ = [IndexS]
try:
from utilities.polars import check_polars_dataframe
except ModuleNotFoundError:
pass
else:
_ = [check_polars_dataframe]
try:
from utilities.pytest import throttle
except ModuleNotFoundError:
pass
else:
_ = [throttle]
try:
from utilities.sqlalchemy import get_table, insert_items
except ModuleNotFoundError:
pass
else:
_ = [get_table, insert_items]
try:
from utilities.sqlalchemy_polars import insert_dataframe
except ModuleNotFoundError:
pass
else:
_ = [insert_dataframe]
try:
from utilities.timer import Timer
from utilities.sqlalchemy_polars import (
insert_dataframe,
insert_dataframe_async,
select_to_dataframe,
select_to_dataframe_async,
)
except ModuleNotFoundError:
pass
else:
_ = [Timer]
_ = [
insert_dataframe,
insert_dataframe_async,
select_to_dataframe,
select_to_dataframe_async,
]


try:
import xarray
from xarray import DataArray, Dataset
except ModuleNotFoundError:
pass
else:
_ = [xarray, DataArray, Dataset]


try:
from whenever import Date, DateTimeDelta, LocalDateTime, Time, ZonedDateTime
except ModuleNotFoundError:
pass
else:
_ = [Date, DateTimeDelta, LocalDateTime, Time, ZonedDateTime]
try:
from utilities.whenever import (
ensure_date,
Expand Down Expand Up @@ -1248,15 +1280,6 @@
serialize_zoned_datetime,
]

try:
import xarray
from xarray import DataArray, Dataset
except ModuleNotFoundError:
pass
else:
_ = [xarray, DataArray, Dataset]


# functions


Expand Down
6 changes: 2 additions & 4 deletions jupyter/docmanager/plugin.jsonc
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
// Document Manager
// @jupyterlab/docmanager-extension:plugin
// Document Manager settings.
// ***************************************
"autosave": false,
"autosaveInterval": 120,
}
33 changes: 32 additions & 1 deletion jupyter/filebrowser/browser.jsonc
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
{
// File Browser
// @jupyterlab/filebrowser-extension:browser
// File Browser settings.
// *****************************************

// Filter folders
// Whether to apply the search on folders
"filterDirectories": true,

// Navigate to current folder
// Whether to automatically navigate to a document's current folder
"navigateToCurrentDirectory": true,

// Use checkboxes to select items
// Whether to show checkboxes next to files and folders
"showFileCheckboxes": false,

// Show file size column
// Whether to show the file size column
"showFileSizeColumn": false,

// Show full path in browser bread crumbs
// Whether to show full path in browser bread crumbs
"showFullPath": false,

// Show hidden files
// Whether to show hidden files. The server parameter `ContentsManager.allow_hidden` must be set to `True` to display hidden files.
"showHiddenFiles": true,
"showLastModifiedColumn": false,

// Show last modified column
// Whether to show the last modified column
"showLastModifiedColumn": true,

// When sorting by name, group notebooks before other files
// Whether to group the notebooks away from files
"sortNotebooksFirst": true,

// Filter on file name with a fuzzy search
// Whether to apply fuzzy algorithm while filtering on file names
"useFuzzyFilter": true,
}
9 changes: 8 additions & 1 deletion nvim/lua/snippets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ ls.add_snippets("python", {
-- hypothesis
s("hy-assume", { t({ "from hypothesis import assume", "" }) }),
s("hy-booleans", { t({ "from hypothesis.strategies import booleans", "" }) }),
s("hy-composite", { t({ "from hypothesis.strategies import composite", "" }) }),
s("hy-data", { t({ "from hypothesis.strategies import data, DataObject", "" }) }),
s("hy-dates", { t({ "from hypothesis.strategies import dates", "" }) }),
s("hy-datetimes", { t({ "from hypothesis.strategies import datetimes", "" }) }),
s("hy-given", { t({ "from hypothesis import given", "" }) }),
s("hy-integers", { t({ "from hypothesis.strategies import integers", "" }) }),
s("hy-invalid-argument", { t({ "from hypothesis.errors import InvalidArgument", "" }) }),
s("hy-lists", { t({ "from hypothesis.strategies import lists", "" }) }),
s("hy-reproduce-failure", { t({ "from hypothesis import reproduce_failure", "" }) }),
s("hy-sampled-from", { t({ "from hypothesis.strategies import sampled_from", "" }) }),
s("hy-settings", { t({ "from hypothesis import settings", "" }) }),
s("settings-max-examples", { t({ "@settings(max_examples=1)", "" }) }),
s("hy-tuples", { t({ "from hypothesis.strategies import tuples", "" }) }),
s("settings-filter-too-much", { t({ "@settings(suppress_health_check={HealthCheck.filter_too_much})", "" }) }),
s("settings-generate-only", { t({ "@settings(phases={Phase.generate})", "" }) }),
s("settings-max-examples", { t({ "@settings(max_examples=1)", "" }) }),

-- itertools
s("it-accumulate", { t({ "from itertools import accumulate", "" }) }),
Expand Down Expand Up @@ -178,6 +182,9 @@ ls.add_snippets("python", {
-- re
s("re-search", { t({ "from re import search", "" }) }),

-- redis
s("re-redis", { t({ "from redis import Redis", "" }) }),

-- rich
s("ri-print", { t({ "from rich import print", "" }), t({ "" }), t({ "print(" }), i(1, "Values"), t({ ")", "" }) }),

Expand Down
Loading

0 comments on commit 95f0c68

Please sign in to comment.